Questions tagged [ruby-on-rails-3.1]

Ruby on Rails version 3.1.0 is a specific version of Ruby on Rails. It was released on August 30th, 2011. Use this tag for issues related to development in Ruby on Rails version 3.1.

Ruby on Rails version 3.1.0 is a specific version of Ruby on Rails.

Released on August 30th, 2011, it was succeeded by version 3.2.0.

It brings many improvements to the Ruby on Rails web development framework, which is open-source and optimized for programmer happiness and maintaining sustainable productivity. Many things are defined by convention, freeing you from having to re-invent things to stay productive.

Version 3.1 brings many improvements over its preceding version 2, including faster ActiveRecord, assets re-structure, coffeescript, sass, and more.

Further Reading:

Related tag

5270 questions
84
votes
4 answers

When to use self in Model?

Question: when do I need to use self in my models in Rails? I have a set method in one of my models. class SomeData < ActiveRecord::Base def set_active_flag(val) self.active_flag = val self.save! end end When I do this, everything works…
varatis
  • 14,494
  • 23
  • 71
  • 114
83
votes
10 answers

rails - "WARNING: Can't verify CSRF token authenticity" for json devise requests

How can I retrieve the CSRF token to pass with a JSON request? I know that for security reasons Rails is checking the CSRF token on all the request types (including JSON/XML). I could put in my controller skip_before_filter…
user1027503
78
votes
10 answers

Rails: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

My website has been broken since Dreamhost upgraded their servers a couple of weeks ago. I have been tearing my hair out trying to get it fixed and made some progress but am stuck on what is hopefully the final issue. I'm using Rails 3.1.1 on Ruby…
Rich
  • 2,164
  • 1
  • 25
  • 39
78
votes
6 answers

Add a new asset path in Rails 3.1

Does anyone know how to add another folder to the asset pipeline in Rails 3.1? I'd like to serve app/assets/fonts the same way app/assets/images is served. Update: 5-7-2013 Just to add some clarification for future people who find this question to…
Andrew
  • 42,517
  • 51
  • 181
  • 281
78
votes
3 answers

Rails: How to add link_to with target blank

I am new to rails 3, I would like to add (:target => "_blank") to link_to helper below link_to "GOOGLE", 'http://www.google.com', class: "btn btn-large btn-primary" But I would like to use the application_helper to define link_to method. How do I…
joe
  • 946
  • 1
  • 7
  • 14
76
votes
4 answers

Can we call a Controller's method from a view (as we call from helper ideally)?

In Rails MVC, can you call a controller's method from a view (as a method could be called call from a helper)? If yes, how?
Manish Shrivastava
  • 30,617
  • 13
  • 97
  • 101
76
votes
6 answers

Rails 3.1 asset pipeline: how to load controller-specific scripts?

If I generate a new controller in Rails 3.1, also a javascript file with the name of the controller will added automatically. Firstly, I thought this javascript file will used only, when the related controller is called. By default there is the…
Mike Bevz
  • 1,266
  • 1
  • 14
  • 20
76
votes
12 answers

How to add confirm message with link_to Ruby on rails

I wanted to add confirmation message on link_to function with Ruby. = link_to 'Reset message', :action=>'reset' ,:confirm=>'Are you sure?' Any ideas why it's not working?
73
votes
1 answer

Access Asset Path from Rails Controller

I'm sharing a configuration yml file client side, that I need to also load on the server side, I've placed it inside app/assets/javascripts/configuration.yml I can use #{asset_path 'configuration.yml'} inside a view to get the path, but I can't…
Marcel M.
  • 2,376
  • 2
  • 18
  • 24
71
votes
5 answers

Ruby syntax: break out from 'each.. do..' block

I am developing a Ruby on Rails app. My question is more about Ruby syntax. I have a model class with a class method self.check: class Cars < ActiveRecord::Base ... def self.check(name) self.all.each do |car| #if result is true,…
Mellon
  • 37,586
  • 78
  • 186
  • 264
66
votes
5 answers

Rails generate Migration

I currently have migration called Products, and I simply want to add few more strings to this migration such as description and product type. What is the best way to do this? class CreateProducts < ActiveRecord::Migration def change …
Ivan Kutsarov
  • 983
  • 1
  • 7
  • 14
65
votes
6 answers

What's the correct syntax for remove_index in a Rails 3.1.0 migration?

I'm in the process of adding Devise to an existing Rails app, with a Users table already defined. The devise generator pushed out the following migration: class AddDeviseToUsers < ActiveRecord::Migration def self.up change_table(:users) do…
doublea
  • 2,546
  • 1
  • 23
  • 35
64
votes
5 answers

Clear the cache from the Rails asset pipeline

I'm starting a new project in Rails, and it looks like the application.js manifest file is doing something funny with the javascripts that I reference - does it cache those files as part of the asset pipeline? Here's what happened. I added a…
61
votes
5 answers

Upgrading from Rails 3 to Rails 3.1

How do you upgrade from Rails 3 to Rails 3.1 beta?
user730569
  • 3,940
  • 9
  • 42
  • 68
61
votes
4 answers

Rails naming convention for join table

This questions stems from: How to link form after creating rails join table I am creating the join table between my Product and Category Models. What should the join table be named? categories_products or category_products or something else?