Add Custom Field/Column to Devise with Rails 4

Once your model has its full_name attribute, you will have to configure permitted parameters for the #sign_up and #account_update Devise actions. class ApplicationController < ActionController::Base before_action :configure_devise_permitted_parameters, if: :devise_controller? protected def configure_devise_permitted_parameters registration_params = [:full_name, :email, :password, :password_confirmation] if params[:action] == ‘update’ devise_parameter_sanitizer.for(:account_update) do |u| u.permit(registration_params << :current_password) end elsif params[:action] == ‘create’ devise_parameter_sanitizer.for(:sign_up) do … Read more

Heroku does NOT compile files under assets pipelines in Rails 4

Heroku’s asset plugins no longer work since Rails 4 does not support plugins. You need to use Heroku’s asset gems instead. Place this in your Gemfile: group :production do gem ‘rails_log_stdout’, github: ‘heroku/rails_log_stdout’ gem ‘rails3_serve_static_assets’, github: ‘heroku/rails3_serve_static_assets’ end Follow Heroku’s guide on getting started with Rails 4. Update (07/22/2013): Heroku now supplies a different gem … Read more

Rails 4 Authenticity Token

I think I just figured it out. I changed the (new) default protect_from_forgery with: :exception to protect_from_forgery with: :null_session as per the comment in ApplicationController. # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. You can see the difference by looking at the source for request_forgery_protecton.rb, … Read more

ActiveRecord OR query Hash notation

There are 5 options that could be considered as implementations of «Hash notation» (the last two are kinda hash-ish): With Ruby on Rails 5 you are able to do the following chaining using ActiveRecord::Relation#or method: Person.where(name: ‘Neil’).or(Person.where(age: 27)) Use where_values together with reduce. The unscoped method is necessary only for Rails 4.1+ to ensure default_scope … Read more

Rails 4: List of available datatypes

Here are all the Rails 4 (ActiveRecord migration) datatypes: :binary :boolean :date :datetime :decimal :float :integer :bigint :primary_key :references :string :text :time :timestamp Source: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column These are the same as with Rails 3. If you use PostgreSQL, you can also take advantage of these: :hstore :json :jsonb :array :cidr_address :ip_address :mac_address They are stored as … Read more