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

Rails 4.2 Server port forwarding on Vagrant does not work

I have a Vagrant VM with Rails installed with a sample app. The VM is configured to forward the port 3000 (of Rails Webrick server) to my host 3000 port. config.vm.network "forwarded_port", guest: 3000, host: 3000 Everything is configured as seen…
Victor Leal
  • 1,055
  • 2
  • 12
  • 28
46
votes
2 answers

rails 4 before_validation on: :create or on: :save

I am having a case which is getting around my head. I have an Image model which I only want to save if it gets uploaded. I also need some information coming from the upload to validate the image(like height and width). But I want only the upload to…
andre.orvalho
  • 1,034
  • 2
  • 11
  • 17
46
votes
8 answers

Rails Responds with 404 on CORS Preflight Options Request

I'm creating a set of services using Rails 4, which I am consuming with a JavaScript browser application. Cross-origin GETS are working fine, but my POSTs are failing the preflight OPTIONS check with a 404 error. At least, I think that's what's…
46
votes
11 answers

ERROR: Failed to build gem native extension on Mavericks

I'm attempting to run bundle in my Rails project on OSX 10.9. It fails when getting to the pg gem with this error: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. …
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263
46
votes
2 answers

Same Rails 4 routes for GET and POST requests

In Rails 3 Match used to point to an action for both "GET" and "POST" and other type of requests. match "user/account" => user#account Now this will point to account action of user's controller for both GET and POST requests. As in Rails 4 "match"…
Adnan Ali
  • 2,890
  • 5
  • 29
  • 50
45
votes
4 answers

How do I schedule recurring jobs in Active Job (Rails 4.2)?

I found this Schedule one-time jobs in Rails but this only shows how schedule one-time. I am interested in scheduling a recurring job. Delayed_job has this self.delay(:run_at => 1.minute.from_now) How do I do something like that in Rails…
luis.madrigal
  • 1,366
  • 1
  • 15
  • 31
45
votes
9 answers

Rails 4, Capistrano 3.0.0, cannot load such file -- deploy

I just ran bundle update and capistrano got updated to 3.0.0 but now when I run cap deploy I get an error and can't figure out how to fix this. I have been updating my server every day without problem until this update. cap aborted! cannot load such…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
45
votes
2 answers

Possible to specify unique index with NULLs allowed in Rails/ActiveRecord?

I want to specify a unique index on a column, but I also need to allow NULL values (multiple records can have NULL values). When testing with PostgreSQL, I see that I can have 1 record with a NULL value, but the next will cause an…
at.
  • 50,922
  • 104
  • 292
  • 461
45
votes
6 answers

Bundler could not find compatible versions for gem “railties” for Rails 4.0.0

I am trying to upgrade to Rails 4.0.0, and I changed the gem versions of sass-rails and coffee-rails. I need to resolve this gem conflict between rails and coffee-rails before I can upgrade to Rails 4. When I ran bundle update this is the output I…
Brian Petersen
  • 491
  • 1
  • 4
  • 5
45
votes
7 answers

Using turbolinks in a Rails link_to

Just wondering whether there's a way to use turbolinks directly in a rails link_to helper, a quick bit of googling didn't uncover anything of note, here's the type of thing I've tried to no avail. <%= link_to 'Giraffe', giraffe_path(@giraffe),…
Gareth Jones
  • 1,760
  • 1
  • 14
  • 24
44
votes
1 answer

Circular dependency detected while autoloading constant when loading constant

First of all: I googled and used the search here and found answers to the same error but on different setups. Maybe I broke sth different ;) Error: RuntimeError at /admin/users Circular dependency detected while autoloading constant…
tomr
  • 1,134
  • 2
  • 10
  • 25
44
votes
5 answers

Asset filtered out and will not be served: add `config.assets.precompile

I just migrated my Application to rails 4.1.0 from 4.1.rc2. Started getting these errors for my JS files ActionView::Template::Error: Asset filtered out and will not be served: add `config.assets.precompile += %w( my_js )` to…
AnkitG
  • 6,438
  • 7
  • 44
  • 72
44
votes
10 answers

Rails 4 - Respond only to JSON and not HTML

I'm trying to build an API in rails 4, and am having an issue where rails returns a 500 error instead of a 406 when using respond_to :json and trying to access the html version. Here's an example controller demonstrating the problem: class…
Tom Brunoli
  • 3,436
  • 9
  • 36
  • 54
44
votes
4 answers

ActionController::InvalidAuthenticityToken when disable JS/Ajax request

I have two forms with option remote: true; one sends an Ajax request to create action and the other one sends an Ajax request to destroy action. All work fines when JavaScript is enabled, but if I disable JavaScript, then I click, I get this…
medBouzid
  • 7,484
  • 10
  • 56
  • 86
44
votes
1 answer

Rails 4 migration: how to reorder columns

I learned that add_column has an :after option to set where the column gets inserted. Too bad I learned about it :after adding a bunch. How can I write a migration to simply reorder columns?
emersonthis
  • 32,822
  • 59
  • 210
  • 375