Rails from with better url

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-04-16T09:40:25Z Indexed on 2010/04/16 9:43 UTC
Read the original article Hit count: 147

Filed under:
|
|

wow, switching to rest is a different paradigm for sure and is mainly a headache right now.

view

<% form_tag (businesses_path, :method => "get") do %>
<%= select_tag :business_category_id, options_for_select(@business_categories.collect     {|bc| [bc.name, bc.id ]}.insert(0, ["All Containers", 0]),  which_business_category(@business_category) ), { :onchange => "this.form.submit();"} %>
<% end %>

controller

def index
@business_categories = BusinessCategory.find(:all)
if params[:business_category_id].to_i != 0
  @business_category = BusinessCategory.find(params[:business_category_id])
  @businesses = @business_category.businesses
else
 @businesses = Business.all 
end
respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @businesses }
end

end

routes

map.resources 

What I want to to is get a better url than what this form is presenting which is the following: http://localhost:3000/businesses?business_category_id=1

Without rest I would have do something like http://localhost:3000/business/view/bbq bbq as permalink or I would have done http://localhost:300/business_categories/view/bbq and get the business that are associated with the category but I don't really know the best way of doing this.

So the two questions are what is the best logic of finding a business by its categories using the latter form and number two how to get that in a pretty url all through restful routes in rails.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about on