‘Nicer’ URLs for Rails

URLs pointing to resources in a Rails app tend to look like www.somesite.com/people/1

Add this to your model:

def to_param

Where title is whatever you want to appear after the id and you will get URLs like


More info from here

Sending lots of data using Post and Rails (ie. avoid URI too long error)

I was having problems with a link to remote that I had encoded as follows:

link_to_remote ‘Variable’, :url=> sort_variables_surveys_url(:sorted_variables=>sorted_variables, :search_query=>query, :survey_list => years, :sort => key)

The sorted_variables param was far too big in some cases and returning a ‘uri too long’ error. ┬áSo I scratched my head for a while and then looking at the link_to_remote docs more closely showed that if I wrapped the ‘sorted_variables’ up inside a div like so:

<div id=”sorted_variables”>

<% sorted_variables.each do |variable| -%>

<%= hidden_field_tag “sorted_variables[]”, variable.id.to_s -%>

<% end -%>


and then added :submit => ‘sorted_variables’ to the link_to_remote call like this:

link_to_remote ‘Variable’, :submit=> ‘sorted_variables’, :url=> sort_variables_surveys_url(:search_query=>query, :survey_list => years, :sort => key)

then it all seems to work fine.