Forum: Ruby on Rails unknown action - incorrect route

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A74096209c78118ff69d50a51129d697?d=identicon&s=25 Jason Lillywhite (jlillywh)
on 2008-10-09 16:43
I have a form called edit.rhtml that lets you edit attributes of an
Event object.
In the file I have the following code:
<% form_tag :action => 'update', :id => @event do %>
  <%= render :partial => 'form' %>
  <%= submit_tag_or_cancel 'Save Changes' %>
<% end %>

The 'update' method in the controller is called to update attributes in
the database. I understand this is my action.
But when I hit the "submit_tag_or_cancel" to save the changes, I get
routed to:

http://localhost:3000/events/8

In the browser I get Unknown Action; No action responded to 8

but I want to get routed back to the list of events:

http://localhost:3000/events

My routes.rb configuration is as follows:
map.edit_event 'events/edit/:id', :controller => 'events', :action =>
'edit'

I've tried changing the <% form_tag code around without success. Thank
you very much for your help!
23e4fc3add5443f51e55663cfc245d24?d=identicon&s=25 Erol Fornoles (Guest)
on 2008-10-09 17:28
(Received via mailing list)
Jason Lillywhite wrote:
> But when I hit the "submit_tag_or_cancel" to save the changes, I get
> My routes.rb configuration is as follows:
> map.edit_event 'events/edit/:id', :controller => 'events', :action =>
> 'edit'
>
> I've tried changing the <% form_tag code around without success. Thank
> you very much for your help!
> --
> Posted via http://www.ruby-forum.com/.

It's probably defaulting to the default route:

map.connect ':controller/:action/:id'

You'll need to specify a route for the :update action, but I think
you're better off using RESTful routes instead:

map.resources :events
A74096209c78118ff69d50a51129d697?d=identicon&s=25 Jason Lillywhite (jlillywh)
on 2009-03-26 07:13
> map.resources :events


OK. I'm still learning about RESTful. I'll study up on that. Thank you!
This topic is locked and can not be replied to.