Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3 routes: different auto route for model

so i've got a model class named Photoset and a controller named Sets. ive got resources :sets working for everything except when paths are generated off an instance of the model. for example if i use:

<%= form_for(@photoset) do |f| %>

i get the error:

 no route matches {:controller=>"sets"}

ultimately i want all the uris to be .../sets/...(controller name) instead of .../photosets/...(model name)

is there any way to do this and still be able to use the helpers?

--EDIT-- heres my rake routes output:

    sets GET    /sets(.:format)          {:controller=>"sets", :action=>"index"}
         POST   /sets(.:format)          {:controller=>"sets", :action=>"create"}
 new_set GET    /sets/new(.:format)      {:controller=>"sets", :action=>"new"}
edit_set GET    /sets/:id/edit(.:format) {:controller=>"sets", :action=>"edit"}
     set GET    /sets/:id(.:format)      {:controller=>"sets", :action=>"show"}
         PUT    /sets/:id(.:format)      {:controller=>"sets", :action=>"update"}
         DELETE /sets/:id(.:format)      {:controller=>"sets", :action=>"destroy"}

that all works just dandy, the problem is when i try to build a form off an instance of the model. I understand that rails has no way of knowing that im trying to tie the Photoset model directly with the Set controller, but I don't know how to specify that.

like image 454
greggreg Avatar asked Jan 05 '11 11:01

greggreg


1 Answers

You have a Photoset model, Sets controller and urls need to be in form /sets/1/edit.

resources :sets, :as => "photosets"

Works with a simple form like this:

<%= form_for(@photoset) do |f| %>
    <%= f.text_field :title %>
    <%= f.submit "Save" %>
<% end %>
like image 142
Heikki Avatar answered Oct 03 '22 17:10

Heikki