Questions tagged [ruby-on-rails-4]

For issues specific to version 4 of Rails. If your question applies to Ruby on Rails in general, use the tag [ruby-on-rails].

Ruby on Rails 4.0, "an open-source web framework that's optimized for programmer happiness and sustainable productivity." Rails 4.0 brings a bunch of new features and improvements over older Rails versions.

See Ruby on Rails 4.0 Release Notes for more information.

Multiple sub-versions have been released, namely 4.0, 4.1 and 4.2. Questions regarding specific sub-versions of Ruby on Rails 4.0 can also be asked on the appropriate tags:

Resources

Related tags

36770 questions
44
votes
7 answers

First argument in form cannot contain nil or be empty - Rails 4

I receive this error with my contact form in rails: First argument in form cannot contain nil or be empty View: <%= form_for @contact do |f| %> and so on....... Controller def new @contact = Contact.new end and so on.... I found…
nil
  • 2,238
  • 1
  • 19
  • 28
44
votes
2 answers

Rails 4 pgsql add_index with type GIN or GiST

In Rails it is possible to do: add_index :table, :column_name, :using => 'btree' Is it possible in Rails 4 with PGSQL to add a GIN or GiST index like: add_index :students, :name, :using => 'gin' Or do I have use manual execute statements? The notion…
Bill
  • 3,059
  • 3
  • 31
  • 47
44
votes
5 answers

Forbidden Attributes Error in Rails 4 when encountering a situation where one would have used attr_accessible in earlier versions of Rails

With the recent upgrade to Rails 4, updating attributes using code resembling the below does not work, I get a ActiveModel::ForbiddenAttributes error: @user.update_attributes(params[:user], :as => :admin) Where User has the following…
43
votes
3 answers

How do I clear my Rails file cache?

I’m running Rails 4.2.7 on Ubuntu 14.04. I have written the following method to help cache some data (preventing hits against my PostGres 9.5 database) … class Country < ActiveRecord::Base has_many :states def self.cached_find_by_iso(iso) …
Dave
  • 15,639
  • 133
  • 442
  • 830
43
votes
3 answers

Rails 4.2: Internal Server Error with Maximum file multiparts in content reached

Just upgraded to Rails 4.2 and I get Internal Server Error on localhost and in production when trying to edit a model with multiple has_many objects. This is the message I see on the rails s console !! Unexpected error while processing request: Too…
anu
  • 1,076
  • 10
  • 20
43
votes
3 answers

Check if DateTime value is today, tomorrow or later

I have an object attribute of the DateTime class. How would I understand if the saved date is today, tomorrow or else later?
Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232
43
votes
5 answers

Is "proc" required with conditional before_action/before_filter?

Behold, a before_filter: class ThingController < ApplicationController before_filter :check_stuff, :if => proc {Rails.env.production?} end During a recent code review, I was asked, "Is the proc is required for this to work?" The answer appears to…
MrTheWalrus
  • 9,670
  • 2
  • 42
  • 66
43
votes
4 answers

No database connection in rails console

My rails application works fine when I run rake db:migrate but the problem occurs when I try to start the rails console. 2.0.0p247 :003 > User => User(no database connection)
ben
  • 6,000
  • 5
  • 35
  • 42
43
votes
10 answers

rails confirm before delete

Here is my rails link_to <%= link_to 'Delete',url_for(action: :delete,id: @user.id),data: {confirm: "Are you sure?"} %> I tried the above method but it is directly deleting without any alert message. What wrong I made. Can any one correct it.
Prabhakaran
  • 3,900
  • 15
  • 46
  • 113
42
votes
1 answer

Exclude a controller from before_action

I am using the before_action filter to call authenticate which is a method that will redirect users back to their home page if they aren't authorized to be on the page requested. I would like to exclude a page from this step, just for testing…
Matt C
  • 4,470
  • 5
  • 26
  • 44
42
votes
3 answers

Gem Vs Plugin Vs Engine in Ruby on Rails

What is the difference between Gem package, plugin, and Engine in Ruby on Rails? I think we use the plugin before Rails3.2 and after rails3.2 is released we are using the gem package as a plugin but how can we use the engine in ROR?
42
votes
7 answers

Error "uninitialized constant AWS (NameError)"

It is saying AWS is uninitialized. I am usign the aws-sdk-core gem. I tried using the aws-sdk gem instead, and the problem was still there. This is the initializers/aws.rb file: AWS.config(:access_key_id => ENV['AWS_ACCESS_KEY_ID'], …
42
votes
4 answers

How to remove Bold from f.label

I'm stylizing a webpage developed on Rails. So, I have a form with the checkbox of password remember. The problem Is it is always on bold and I can't change it. I've changed successfully the font-style, to italic, the color, but I couldn't remove…
kamusett
  • 1,403
  • 1
  • 12
  • 22
42
votes
1 answer

Detect user agent in Rails 4 - read HTTP header

I just switched from PHP to Ruby on Rails and was wondering if there was a way to detect the clients device/user agent (reading the HTTP header) in order to serve different versions of the site depending on the request it gets. In PHP I have been…
Severin
  • 8,508
  • 14
  • 68
  • 117
42
votes
1 answer

How to redirect with a 301 or 302 in the routes.rb

How can you redirect using a 302 from within the routes.rb file?
Tom Rossi
  • 11,604
  • 5
  • 65
  • 96