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
50
votes
3 answers

has_many :through with class_name and foreign_key

I'm working with a fairly straightforward has_many through: situation where I can make the class_name/foreign_key parameters work in one direction but not the other. Perhaps you can help me out. (p.s. I'm using Rails 4 if that makes a…
JCQ
  • 623
  • 1
  • 5
  • 8
49
votes
2 answers

expected true to respond to true?

I upgraded my rspec-rails to 3.0.1 and now I'm seeing this error on all of my tests Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true expected true to respond to `true?` I can't find the solution nor what I'm missing.
Luiz E.
  • 6,769
  • 10
  • 58
  • 98
49
votes
5 answers

ERROR: zero-length delimited identifier at or near """" LINE 1: DELETE FROM "regions" WHERE "regions"."" = $1

I'm using Rails 4.1 and Postgresql (with PG gem) as my database. I have a very stand many to many association from companies to provinces with a join table called regions. Now obviously the regions table has no primary key cause I used { :id =>…
Steve
  • 561
  • 2
  • 5
  • 7
49
votes
10 answers

What's the 'Rails 4 Way' of finding some number of random records?

User.find(:all, :order => "RANDOM()", :limit => 10) was the way I did it in Rails 3. User.all(:order => "RANDOM()", :limit => 10) is how I thought Rails 4 would do it, but this is still giving me a Deprecation warning: DEPRECATION WARNING:…
justindao
  • 2,273
  • 4
  • 18
  • 34
48
votes
6 answers

In Rails 4.1, how to find records by enum symbol?

Assume I have this model: class Conversation < ActiveRecord::Base enum status: [ :active, :archived ] end How can I find all active conversations without using the numeric value of the enum or without having to iterate over each conversation? …
48
votes
7 answers

Strong parameters require multiple

I'm receiving a JSON package like: { "point_code" : { "guid" : "f6a0805a-3404-403c-8af3-bfddf9d334f2" } } I would like to tell Rails that both point_code and guid are required, not just permitted. This code seems to work but I don't think it's…
Rob
  • 7,028
  • 15
  • 63
  • 95
48
votes
5 answers

ActionMailer not sending mail in development Rails 4

Why is this mailer not sending any mail? (Or any ideas for debugging?) In my_app/config/environments/development.rb I have this code: config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: …
Don P
  • 60,113
  • 114
  • 300
  • 432
48
votes
8 answers

How do you initialize an ActiveModel::Serializer class with an ActiveRecord::Relation array?

I have a serializer class FundingSerializer < ActiveModel::Serializer attributes :id, has_one :user has_one :tournament embed :ids, include: true end That initializes with the proper…
shicholas
  • 6,123
  • 3
  • 27
  • 38
47
votes
10 answers

"undefined method `env' for nil:NilClass" in 'setup_controller_for_warden' error when testing Devise using Rspec

I'm trying to create a spec for a sign out flow by using factorygirl to create a user and then use Devise's sign_in method to authenticate the user, then use capybara to click the "Sign Out" link. I'm getting (what seems to me to be) a strange error…
jpalmieri
  • 1,539
  • 1
  • 15
  • 25
47
votes
5 answers

Rails: DEPRECATION WARNING: You didn't set config.secret_key_base

I receive this warning when running my specs. Is there a best practice for generating a secret_key_base, or will any string suffice (with regard to security concerns)?
Caleb
  • 3,692
  • 3
  • 24
  • 28
47
votes
5 answers

Why use 'reload' method after saving object? (Hartl Rails Tut 6.30)

I'm working on the exercises for chapter 6 of Hartl's Rails 4 Tutorial. The first exercise tests to make sure that user email addresses are down-cased correctly: require 'spec_helper' describe User do . . . describe "email address with…
sixty4bit
  • 7,422
  • 7
  • 33
  • 57
47
votes
3 answers

How can we set the name of the email sender in Rails Mailer?

Whenever I send an email through my Rails app, in my inbox, the name of the sender is shown as "admin".. The email is admin@... The first part of the domain is shown. Im using Mandrill to send the email. How can I change this name?
THpubs
  • 7,804
  • 16
  • 68
  • 143
47
votes
1 answer

Rails generate has_many association

Is there a way to generate has_many association for a column using Rails generate scaffold command in the console? I know belongs_to is available and there are use cases of references but not sure of has_many
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
47
votes
3 answers

Rails 4 turbo-link prevents jQuery scripts from working

I'm building a Rails 4 app and I have a few scattered js files that I'm trying to include "the rails way". I moved jquery plugins into the /vendor/assets/javascripts and I updated the manifest (application.js) to require them. When I load the pages…
emersonthis
  • 32,822
  • 59
  • 210
  • 375
46
votes
1 answer

Rails NoMethodError: undefined method new for BigDecimal:Class

My app is on: ruby-2.6.4 Rails 4.2.8 activerecord-4.2.8 I'm upgrading a rails app to ruby-2.6.4 When running a rake task in development, for testing, I am getting errors for BigDecimal() and…
John Cowan
  • 1,452
  • 5
  • 25
  • 39