Flowdock

Notes posted by batasrki

RSS feed
October 24, 2012
2 thanks

To add an ID to the form

Found this the hard way, but to add an ID to the form generated by form_tag, you must explicitly make hashes.

Add ID

<%= form_tag({:action => 'create'}, {:id => 'anID'}) %>
March 27, 2009
4 thanks

Usage

Here’s how to use it, just so it’s perfectly clear:

skip_before_filter :method_to_skip, :only => [:method_name]
March 6, 2009
2 thanks

Selected parameter needs an int

In order to pre-select an option, you can pass a fourth parameter. However, that parameter MUST be of integer type, so if you’re trying to set selected from the params hash, you must add to_i at the end of it.

<%= select_tag("job[state_id]", options_from_collection_for_select(State.find(:all), "id", "name", params[:state_id].to_i)) %>
March 3, 2009
0 thanks

Specify controller

If needed, you can also specify a controller.

redirect_to :controller => 'post', :action => 'index'
March 3, 2009 - (<= v2.2.1)
1 thank

Multiple associations on the same level

You can also specify multiple associations that are on the same level, like this:

konata = User.find(1)
konata.to_json(:include => [:posts, :roles])

{"id": 1, "name": "Konata Izumi", "age": 16,
 "created_at": "2006/08/01", "awesome": true,
 "posts": [{"id": 1, "author_id": 1, "title": "Welcome to the weblog"},
           {"id": 2, author_id: 1, "title": "So I was thinking"}],
 "roles": [{"id":1, "user_id":1, "name": "Admin"},
           {"id":2, "user_id":1, "name": "Moderator"}]}