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

36667 questions
798
votes
17 answers

How to get a random number in Ruby

How do I generate a random number between 0 and n?
Mark A. Nicolosi
  • 72,599
  • 10
  • 41
  • 46
634
votes
6 answers

How to use concerns in Rails 4

The default Rails 4 project generator now creates the directory "concerns" under controllers and models. I have found some explanations about how to use routing concerns, but nothing about controllers or models. I am pretty sure it has to do with…
yagooar
  • 15,789
  • 6
  • 17
  • 21
428
votes
19 answers

Rails 4: how to use $(document).ready() with turbo-links

I ran into an issue in my Rails 4 app while trying to organize JS files "the rails way". They were previously scattered across different views. I organized them into separate files and compile them with the assets pipeline. However, I just learned…
emersonthis
  • 30,934
  • 52
  • 191
  • 328
421
votes
5 answers

Rails 4: List of available datatypes

Where can I find a list of data types that can be used in Ruby on Rails 4? Such as text string integer float date I keep learning about new ones and I'd love to have a list I could easily refer to.
Nicolas Raoul
  • 55,003
  • 52
  • 197
  • 338
395
votes
4 answers

Rails update_attributes without save?

Is there an alternative to update_attributes that does not save the record? So I could do something like: @car = Car.new(:make => 'GMC') #other processing @car.update_attributes(:model => 'Sierra', :year => "2012", :looks => "Super Sexy, wanna make…
tybro0103
  • 43,805
  • 32
  • 138
  • 167
387
votes
5 answers

Rails I18n validation deprecation warning

I just updated to rails 4.0.2 and I'm getting this warning: [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to…
Mauricio Moraes
  • 6,889
  • 5
  • 34
  • 54
349
votes
5 answers

Rails 4: before_filter vs. before_action

In rails >4.0.0 generators creates CRUD operations with before_action not before_filter. It seems to do the same thing. So what's the difference between these two?
freemanoid
  • 13,958
  • 6
  • 46
  • 76
330
votes
7 answers

Add a reference column migration in Rails 4

A user has many uploads. I want to add a column to the uploads table that references the user. What should the migration look like? Here is what I have. I'm not sure if I should use (1) :user_id, :int or (2) :user, :references. I'm not even sure if…
Don P
  • 49,839
  • 95
  • 259
  • 394
293
votes
36 answers

PG::ConnectionBad - could not connect to server: Connection refused

Every time I run my rails 4.0 server, I get this output. Started GET "/" for 127.0.0.1 at 2013-11-06 23:56:36 -0500 PG::ConnectionBad - could not connect to server: Connection refused Is the server running on host "localhost" (::1) and…
fadelakin
  • 3,333
  • 4
  • 17
  • 20
261
votes
5 answers

How is attr_accessible used in Rails 4?

attr_accessible seems to no longer work within my model. What is the way to allow mass assignment in Rails 4?
user2532974
  • 2,737
  • 3
  • 10
  • 6
230
votes
4 answers

Auto-loading lib files in Rails 4

I use the following line in an initializer to autoload code in my /lib directory during development: config/initializers/custom.rb: RELOAD_LIBS = Dir[Rails.root + 'lib/**/*.rb'] if Rails.env.development? (from Rails 3 Quicktip: Auto reload lib…
Yarin
  • 144,097
  • 139
  • 361
  • 489
227
votes
5 answers

Paperclip::Errors::MissingRequiredValidatorError with Rails 4

I'm getting this error when I try to upload using paperclip with my rails blogging app. Not sure what it is referring to when it says "MissingRequiredValidatorError" I thought that by updating post_params and giving it :image it would be fine, as…
nadia
  • 2,489
  • 4
  • 13
  • 12
209
votes
17 answers

Rails: How to reference images in CSS within Rails 4

There's a strange issue with Rails 4 on Heroku. When images are compiled they have hashes added to them, yet the reference to those files from within CSS don't have the proper name adjusted. Here's what I mean. I have a file called logo.png. Yet…
Nick ONeill
  • 7,041
  • 9
  • 38
  • 56
199
votes
13 answers

Rails 4 Authenticity Token

I was working on a new Rails 4 app (on Ruby 2.0.0-p0) when I ran into some authenticity token problems. While writing a controller that responds to json (using the respond_to class method), I got to the create action I started getting…
alexcoco
  • 6,637
  • 6
  • 23
  • 39
174
votes
15 answers

How to solve error "Missing `secret_key_base` for 'production' environment" (Rails 4.1)

I created a Rails application, using Rails 4.1, from scratch and I am facing a strange problem that I am not able to solve. Every time I try to deploy my application on Heroku I get an error 500: Missing `secret_key_base` for 'production'…
Paolo Laurenti
  • 2,364
  • 2
  • 12
  • 18
1
2 3
99 100