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
61
votes
7 answers

rails-rspec error cannot load such file -- rspec/core/formatters/progress_formatter

I've broken my rails-rspec. I switched to a different gemset to run a 3rd party test. When I returned to my 2.3.0(default) gemset, I had the following errors. running rspec…
Sawyer Merchant
  • 1,243
  • 2
  • 12
  • 21
61
votes
3 answers

Add nullable foreign key in Rails

Referencing to Rails 4.2 add_foreign_key support: # add a foreign key to `articles.author_id` referencing `authors.id` add_foreign_key :articles, :authors How to create a nullable foreign key constraint, to allow the situation, where…
61
votes
2 answers

Guard with RSpec on Rails 4 giving a lot of warnings

I'm wondering how I can turn off all these warnings when running a simple test: [1] guard(main)> 16:59:46 - INFO - Run all 16:59:46 - INFO - Running all specs /Users/esjd/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:124:…
foobar
  • 10,854
  • 18
  • 58
  • 66
61
votes
4 answers

Ruby on rails 4 app does not work in iframe

How can I embed my rails app into another website via iframe? It works nicely with RoR 3, but not with RoR 4: I tried to use verify_authenticity_token…
Oleg Pasko
  • 2,831
  • 5
  • 35
  • 44
60
votes
4 answers

How to specify devise_parameter_sanitizer for edit action?

I've added Devise to my Rails 4 application, and successfully added username etc. to my User model. Furthermore, I'm able to store those fields using the lazy way™, i.e. class ApplicationController < ActionController::Base before_filter…
conciliator
  • 6,078
  • 6
  • 41
  • 66
59
votes
16 answers

Rails: NameError: uninitialized constant

I have a simple model called PhoneNumber: class PhoneNumber < ActiveRecord::Base validates :pnumber, presence: true, on: :create #=> { :message => " cannot be blank" } validates :pnumber, numericality: true, on: :create end I go to the root…
Nick
  • 2,924
  • 4
  • 36
  • 43
59
votes
4 answers

Using logger in Rails 4

I'm working on a Rails 4 project, and I can't seem to make anything show up in my development log when I call Rails.logger.debug "test" I've tried searching online but I feel like I haven't made much progress. How would I go about setting up a…
Michael Liu
  • 1,071
  • 3
  • 12
  • 18
59
votes
8 answers

"bin/rails: No such file or directory" w/ Ruby 2 & Rails 4 on Heroku

While following the Rails 4 Beta version of Michael Hartl's Ruby on Rails Tutorial, my app fails to start on Heroku, but runs fine locally with bundle exec rails server. Checking heroku logs -t reveals the following error: $ heroku[web.1]: State…
Justin Garrick
  • 14,767
  • 7
  • 41
  • 66
58
votes
1 answer

Where is the default "Welcome Aboard" page located in my app?

I scoured my app's directories, and I can't find the html page for the default rails Welcome Aboard page. I also cannot find a route for the default Welcome Aboard page in routes.rb. How does my rails app route http://localhost:3000/ to a…
7stud
  • 46,922
  • 14
  • 101
  • 127
57
votes
5 answers

Rails: How to use dependent: :destroy in rails?

I have 2 models as describes below. class EmpGroup < ActiveRecord::Base belongs_to :user has_many :emp_group_members, dependent: :destroy end and class EmpGroupMember < ActiveRecord::Base belongs_to :emp_group belongs_to :user end now the…
57
votes
3 answers

Custom error pages for 404, 500 but where is the default 500 error message coming from?

Currently in production I'm getting this text: 500 Internal Server Error If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong. There isn't any…
Rubytastic
  • 15,001
  • 18
  • 87
  • 175
56
votes
1 answer

Rails validates_presense not validating on boolean?

So, I have a form, using a boolean to select male or female. When i use validates :presense for the boolean fields, it returns back, gender cannot be blank! Wehn I remove the validates portion, it lets it pass through as true or false into the DB.…
keith
  • 651
  • 2
  • 6
  • 10
56
votes
7 answers

ActionController::UnknownFormat

In my rails app I have a ajax request to the server, to store some data. This used to work without any problem, but now I get an error: ActionController::UnknownFormat (ActionController::UnknownFormat): …
tvieira
  • 1,865
  • 3
  • 28
  • 45
56
votes
6 answers

Schema Migrations Table

In my Rails 4 app I would like to collapse my migration files into one large file (similar to schema.rb) as it's time to do some housekeeping but I'm not sure on how to access the table in the database that stores migration data so that when I run a…
tommyd456
  • 10,443
  • 26
  • 89
  • 163
55
votes
3 answers

Rails: respond_to JSON and HTML

I have a controller "UserController" that should respond to normal and ajax requests to http://localhost:3000/user/3. When it is a normal request, I want to render my view. When it is an AJAX request, I want to return JSON. The correct approach…
Don P
  • 60,113
  • 114
  • 300
  • 432