Rails 4 Authenticity Token

I was working on a new Rails 4 app (on Ruby 2.0.0-p0) when I ran into some authenticity token problems. While writing a controller that responds to json (using the respond_to class method), I got to the create action I started getting ActionController::InvalidAuthenticityToken exceptions when I tried to create a record using curl. I made … Read more

Paperclip::Errors::MissingRequiredValidatorError with Rails 4

I’m getting this error when I try to upload using paperclip with my rails blogging app. Not sure what it is referring to when it says “MissingRequiredValidatorError” I thought that by updating post_params and giving it :image it would be fine, as both create and update use post_params Paperclip::Errors::MissingRequiredValidatorError in PostsController#create Paperclip::Errors::MissingRequiredValidatorError Extracted source (around … Read more

Auto-loading lib files in Rails 4

I use the following line in an initializer to autoload code in my /lib directory during development: config/initializers/custom.rb: RELOAD_LIBS = Dir[Rails.root + ‘lib/**/*.rb’] if Rails.env.development? (from Rails 3 Quicktip: Auto reload lib folders in development mode) It works great, but it’s too inefficient to use in production- Instead of loading libs on each request, I … Read more

Add a reference column migration in Rails 4

A user has many uploads. I want to add a column to the uploads table that references the user. What should the migration look like? Here is what I have. I’m not sure if I should use (1) :user_id, :int or (2) :user, :references. I’m not even sure if (2) works. Just trying to do … Read more

Rails I18n validation deprecation warning

I just updated to rails 4.0.2 and I’m getting this warning: [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. Is there any security issue in setting it to false? 5 Answers 5

Rails update_attributes without save?

Is there an alternative to update_attributes that does not save the record? So I could do something like: @car = Car.new(:make => ‘GMC’) #other processing @car.update_attributes(:model => ‘Sierra’, :year => “2012”, :looks => “Super Sexy, wanna make love to it”) #other processing @car.save BTW, I know I can @car.model=”Sierra”, but I want to update them … Read more

Rails 4: how to use $(document).ready() with turbo-links

I ran into an issue in my Rails 4 app while trying to organize JS files “the rails way”. They were previously scattered across different views. I organized them into separate files and compile them with the assets pipeline. However, I just learned that jQuery’s “ready” event doesn’t fire on subsequent clicks when turbo-linking is … Read more