gem install rails
rails new my_app -T
| diff --git a/Guardfile b/Guardfile | |
| index 90843a8..6ffae21 100644 | |
| --- a/Guardfile | |
| +++ b/Guardfile | |
| @@ -1,7 +1,7 @@ | |
| # A sample Guardfile | |
| # More info at https://github.com/guard/guard#readme | |
| -guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do | |
| +guard 'spork', :wait => 60, :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do |
| class Key < ActiveRecord::Base | |
| has_secure_password | |
| belongs_to :user | |
| attr_accessible :title, :password, :password_confirmation, :old_password | |
| before_validation :strip_values #, :set_password | |
| validates :title, :length => { :within => 3..254 } | |
| validates :user_id, :presence => true |
| # encoding: utf-8 | |
| ActiveAdmin::Views::Pages::Base.class_eval do | |
| private | |
| # Renders the content for the footer | |
| def build_footer | |
| div :id => "footer" do | |
| para "Copyright © #{Date.today.year.to_s} #{link_to('Example.com', 'http://example.com')}. Powered by #{link_to('Active Admin', 'http://www.activeadmin.info')} #{ActiveAdmin::VERSION}".html_safe | |
| end | |
| end | |
| end |
| CarrierWave.configure do |config| | |
| config.fog_credentials = { | |
| :provider => 'AWS', # required | |
| :aws_access_key_id => 'my_access_key', # required | |
| :aws_secret_access_key => 'my_secret_access_key', # required | |
| :region => 'us-east-1' # optional, defaults to 'us-east-1' | |
| } | |
| config.fog_directory = 'my_bucket_name' # required | |
| config.fog_host = 'https://my_bucket_name.s3.amazonaws.com' # optional, defaults to nil | |
| config.fog_public = false # optional, defaults to true |
It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media
This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.
| class Api::RegistrationsController < Api::BaseController | |
| respond_to :json | |
| def create | |
| user = User.new(params[:user]) | |
| if user.save | |
| render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201 | |
| return | |
| else |
| # ... | |
| gem 'carrierwave' | |
| gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL |
| class EvilObject | |
| class << self | |
| def const_defined?(*) | |
| true | |
| end | |
| def const_get(*) | |
| Object | |
| end |
This is a Rails 5 adaptation of an answer to a StackOverflow question regarding using jQuery UJS to display AJAX-retrieved content in a modal. Here is the original answer:
http://stackoverflow.com/questions/5766055/jquery-modal-windows-and-edit-object/5766232#5766232