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
81
votes
1 answer

Rails 4: organize rails models in sub path without namespacing models?

Would it be possible to have something like this? app/models/ app/models/users/user.rb app/models/users/education.rb The goal is to organize the /app/models folder better, but without having to namespace the models. An unanswered question for Rails…
Rubytastic
  • 15,001
  • 18
  • 87
  • 175
81
votes
5 answers

Active admin install with Rails 4

I got this error when installing active admin on Rails 4 Bundler could not find compatible versions for gem "actionpack": In Gemfile: meta_search (>= 1.1.0.pre) ruby depends on actionpack (~> 3.1.0.alpha) ruby rails (= 4.0.0.rc1) ruby…
Md Sirajus Salayhin
  • 4,974
  • 5
  • 37
  • 46
80
votes
7 answers

'rails generate' commands hang when trying to create a model

I'm new to rails and decided this morning to dump my whole database design/model and start over. And being a noob, I'm sure did it incorrectly. I removed all the files in db/migrate/ and dropped the tables. And when I tried to generate the first new…
Bret
  • 1,455
  • 2
  • 16
  • 27
79
votes
4 answers

Rails API : Best way to implement authentication?

I'm writing a Rails 4 app that will expose an API for a mobile app that's yet to be developed. Users will authenticate using an e-mail and password from the mobile app. While I've found quite a bit of information on the topic. It's hard to discern…
Roma149
  • 1,401
  • 1
  • 12
  • 11
79
votes
2 answers

What is the use of secret_key_base in rails 4

I am new to Rails 4, and do not understand the use of secret_key_base under config/secrets.yml in Rails 4. Can you please explain this concept? Also, when I am working in the production environment, I am prompted to set the secret_key with…
79
votes
5 answers

What is the difference between Workers and Threads in Puma

What is the difference between a puma worker and a puma thread in context of a heroku dyno? What I know (please correct me if I am wrong): Thin is not concurrent, so a web process can only do one request at a time In unicorn, I know I can have…
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
78
votes
9 answers

Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)

I try to run my rails c but for some reason, I get this error: https://gist.github.com/anonymous/166713e8cde860fb188a8dffb98a1563 ᐅ rails c Running via Spring preloader in process…
Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
78
votes
4 answers

With Rails 4, Model.scoped is deprecated but Model.all can't replace it

Starting Rails 4, Model.scoped is now deprecated. DEPRECATION WARNING: Model.scoped is deprecated. Please use Model.all instead. But, there's a difference inModel.scoped and Model.all, that is, scoped.scoped returns a scope, while all.all runs the…
kenn
  • 3,303
  • 2
  • 29
  • 42
78
votes
5 answers

JQuery gets loaded only on page refresh in Rails 4 application

I have created a Rails 4 application and have added fancybox library for an image popup effect. It works fine but only when the page is being refreshed. If the page is not refreshed by the user then the jquery does not work at all. I tried testing…
vishB
  • 1,688
  • 2
  • 17
  • 23
77
votes
5 answers

What is the equivalent of the has_many 'conditions' option in Rails 4?

Can someone tell me what is the equivalent way to do the following line in Rails 4? has_many :friends, :through => :friendships, :conditions => "status = 'accepted'", :order => :first_name I tried the following: has_many :friends, -> { where…
medBouzid
  • 7,484
  • 10
  • 56
  • 86
77
votes
16 answers

Heroku does NOT compile files under assets pipelines in Rails 4

Everything goes well in local machine with assets pipeline in Rails 4 and Ruby 2.0. But when deploying to heroku, it is shown that: -----> Preparing app for Rails asset pipeline Running: rake assets:precompile I, [2013-03-12T03:28:29.908234…
aquajach
  • 2,548
  • 2
  • 23
  • 29
74
votes
2 answers

ActiveRecord OR query Hash notation

I know there are 3 main notations for supplying arguments to the where ActiveRecord method: Pure String Array Hash Specifying and for the where method is straight forward: # Pure String notation Person.where("name = 'Neil' AND age = 27") # Array…
74
votes
8 answers

Rails 4 default scope

In my Rails app have a default scope that looks like this: default_scope order: 'external_updated_at DESC' I have now upgraded to Rails 4 and, of course, I get the following deprecation warning "Calling #scope or #default_scope with a hash is…
Joe Gatt
  • 2,197
  • 3
  • 15
  • 19
72
votes
2 answers

Why Rails 5 uses ApplicationRecord instead of ActiveRecord::Base?

We know that Rails 5 added ApplicationRecord as an abstract class which was inherited by our models (ActiveRecord). But basically, I think every technical requirement we do with ApplicationRecord, we can also do with ActiveRecord::Base. For…
Hieu Pham
  • 6,577
  • 2
  • 30
  • 50
72
votes
6 answers

How to display a Rails flash notice upon redirect?

I have the following code in a Rails controller: flash.now[:notice] = 'Successfully checked in' redirect_to check_in_path Then in the /check_in view:

<%= notice %>

However, the notice does not show up. Works perfect if I don't…
at.
  • 50,922
  • 104
  • 292
  • 461