# Routing

**URL:** <https://www.ruby-forum.com/t/routing/165516>\
**Category:** Rails\
**Created:** [April 14, 2009, 6:47pm UTC](https://www.ruby-forum.com/t/routing/165516 "2009-04-14T18:47:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![srj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srj](https://www.ruby-forum.com/u/srj)\
**Post date:** [April 14, 2009, 6:47pm UTC](https://www.ruby-forum.com/t/routing/165516/1 "2009-04-14T18:47:47Z")

</div>

I have an index page that shows each of my Customers, and each row in  
the display has an Update link which routes to my update method. That  
simply does a find on the Customer id from the link and sets an  
instance variable for the update view.

My update view renders a partial (same one used in the new/create) and  
uses the following form:

I have code in the edit method to get all the updated fields and  
persist the changes. However, when I click on the submit button, the  
update action is executed, not the edit action.

I thought it may be something to do with Rails automatic routing, so I  
renamed the update and edit actions to something very unusual (“edit”  
was renamed to “sally”, and “update” was renamed to “frank”) - same  
results - I wanted sally, but got frank.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![srj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srj](https://www.ruby-forum.com/u/srj)\
**Post date:** [April 14, 2009, 7:03pm UTC](https://www.ruby-forum.com/t/routing/165516/2 "2009-04-14T19:03:31Z")

</div>

Usually the ‘edit’ action is the one that creates the page with the  
form, and the form calls the ‘update’ action. Usually there is no  
update view, the update action will usually redirect to the show page  
for that object or the index page for all objects of that type, or will  
re-render the edit page if the object couldn’t be saved (because it  
fails validations, most commonly).

So, your links should go to the ‘edit’ action, not to ‘update’.

The reason the form doesn’t work is you’re putting attributes in that it  
doesn’t know about, like controller: form tags just take an ‘action’  
attribute, which is the url to submit the form to. However, hard coding  
forms is bad. Use form\_for to make your form, which should look like  
this:

\<%= form\_for @your\_object do |f|%\>  
\<% f.text\_field :name %\>  
…etc  
\<% end %\>

This will submit to the update action automatically

---

<div class="post-metadata">

**Author:** ![srj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srj](https://www.ruby-forum.com/u/srj)\
**Post date:** [April 15, 2009, 5:09am UTC](https://www.ruby-forum.com/t/routing/165516/3 "2009-04-15T05:09:34Z")

</div>

Thank you for the help, Max - I am making progress, but still have  
an issue I cannot figure out.

The reason I was hard coding the form is because when I used the  
form\_for, I was getting unexpected results and errors (I cannot  
remember now what they were). But now that I go back to using  
form\_for, I get an error like this:

```
 Unknown action

 No action responded to 3. Actions: create, edit, index, new, and

```

update

(In this case, 3 is the id of my Customer. If I select a different  
customer, I get that id in the error message.)

Any ideas on that error?

Thanks again,

Steve

On Apr 14, 1:03 pm, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
