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
112
votes
5 answers

Deprecated warning for Rails 4 has_many with order

class RelatedList < ActiveRecord::Base extend Enumerize enumerize :list_type, in: %w(groups projects) belongs_to :content has_many :contents, :order => :position end I have this model in my rails app which throws warning when I try to…
shankardevy
  • 4,290
  • 5
  • 32
  • 49
107
votes
5 answers

Safe ActiveRecord like query

I'm trying to write LIKE query. I read that pure string quires aren't safe, however I couldn't find any documentation that explain how to write safe LIKE Hash Query. Is it possible? Should I manually defend against SQL Injection?
Gal Weiss
  • 1,307
  • 3
  • 9
  • 8
105
votes
18 answers

Error when trying to install app with mysql2 gem

Im trying to install an open source rails 3.2.21 application that uses the mysql2 gem, but when i try and run the bundle commant I get the following error: Fetching: mysql2-0.3.18.gem (100%) Building native extensions. This could take a…
zenvelope
  • 1,274
  • 2
  • 9
  • 13
103
votes
7 answers

Rails 4 image-path, image-url and asset-url no longer work in SCSS files

Are we supposed to use something else aside from image-url and others in Rails 4? They return different values that don't seem to make sense. If I have logo.png in /app/assets/images/logo.png and I do the following, this is what I…
at.
  • 50,922
  • 104
  • 292
  • 461
100
votes
3 answers

Why did Rails4 drop support for "assets" group in the Gemfile

In Rails 3, gems used exclusively to generate assets in the asset pipeline were properly placed in the assets group of the Gemfile: ... # Gems used only for assets and not required # in production environments by default. group :assets do gem…
jemmons
  • 18,605
  • 8
  • 55
  • 84
97
votes
2 answers

Deprecation warning when using has_many :through :uniq in Rails 4

Rails 4 has introduced a deprecation warning when using :uniq => true with has_many :through. For example: has_many :donors, :through => :donations, :uniq => true Yields the following warning: DEPRECATION WARNING: The following options in your…
Ryenski
  • 9,582
  • 3
  • 43
  • 47
96
votes
3 answers

how to know what is NOT thread-safe in ruby?

starting from Rails 4, everything would have to run in threaded environment by default. What this means is all of the code we write AND ALL the gems we use are required to be threadsafe so, I have few questions on this: what is NOT thread-safe in…
CuriousMind
  • 33,537
  • 28
  • 98
  • 137
94
votes
8 answers

Rails association with multiple foreign keys

I want to be able to use two columns on one table to define a relationship. So using a task app as an example. Attempt 1: class User < ActiveRecord::Base has_many :tasks end class Task < ActiveRecord::Base belongs_to :owner, class_name:…
93
votes
4 answers

How to override X-Frame-Options for a controller or action in Rails 4

Rails 4 appears to set a default value of SAMEORIGIN for the X-Frame-Options HTTP response header. This is great for security, but it does not allow for parts of your app to be available in an iframe on a different domain. You can override the value…
92
votes
18 answers

Rails: How to use i18n with Rails 4 enums

Rails 4 Active Record Enums are great, but what is the right pattern for translating with i18n?
Chris Beck
  • 1,899
  • 2
  • 19
  • 26
90
votes
13 answers

LEFT OUTER JOIN in Rails 4

I have 3 models: class Student < ActiveRecord::Base has_many :student_enrollments, dependent: :destroy has_many :courses, through: :student_enrollments end class Course < ActiveRecord::Base has_many :student_enrollments, dependent:…
Khanetor
  • 11,595
  • 8
  • 40
  • 76
89
votes
17 answers

An error occurred while installing pg (0.17.1), and Bundler cannot continue

I just installed Rails 4.0.2 and when creating a new app, in the bundle stage I get: Installing pg (0.17.1) Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/Dee/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb…
Deekor
  • 9,144
  • 16
  • 69
  • 121
84
votes
2 answers

In Rails, what's the difference between find_each and where?

In Rails, both find_each and where are used for retrieving data from Database supported by ActiveRecord. You can pass your query condition to where, like: c = Category.where(:name => 'Ruby', :position => 1) And you can pass batch size to find_each,…
coderz
  • 4,847
  • 11
  • 47
  • 70
84
votes
6 answers

Rails 4 multiple image or file upload using carrierwave

How can I upload multiple images from a file selection window using Rails 4 and CarrierWave? I have a post_controller and post_attachments model. How can I do this? Can someone provide an example? Is there a simple approach to this?
SSR
  • 6,398
  • 4
  • 34
  • 50
82
votes
5 answers

Generate migration - create join table

I have looked through many SO and google posts for generating migration of join table for has many and belongs to many association and nothing work. All of the solutions are generating a empty migration file. I am using rails 3.2.13 and I have two…
gotqn
  • 42,737
  • 46
  • 157
  • 243