# Problem Routing form\_for to update action

**URL:** <https://www.ruby-forum.com/t/problem-routing-form-for-to-update-action/196783>\
**Category:** Rails\
**Created:** [August 14, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/problem-routing-form-for-to-update-action/196783 "2008-08-14T16:17:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a9a28c/32.png) [@mikej](https://www.ruby-forum.com/u/mikej)\
**Post date:** [August 14, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/problem-routing-form-for-to-update-action/196783/1 "2008-08-14T16:17:12Z")

</div>

I have a controller to edit titles and text\_html for a given client.

route to page:

mynamespace/mycontroller/client-permalink/edit

def edit

```
@client = Client.find_by_permalink(params[:id])

if Title.exists?(['client_id = ? AND page_id = 10', @client.id])
  @title=Title.find(:last,:conditions => ['client_id = ? AND

```

page\_id = 10’, @client.id])  
else  
@title=Title.new  
end

```
if TextHtml.exists?(['client_id = ? AND page_id = 10',

```

@client.id])  
@text\_html=TextHtml.find(:last,:conditions =\> [‘client\_id = ?  
AND page\_id = 10’, @client.id])  
else  
@text\_html=TextHtml.new  
end  
end

edit.html.erb:

\<% form\_for :client\_title\_text, :url =\> {:action =\> :update, :id =\>  
@client.permalink} do |form| %\>

```
 <% fields_for :title do |t| %>
 Title: <%= t.text_field :title %><br/>
 <% end %>

 <% fields_for :text_html do |th| %>
 Title: <%= th.text_field :text_html %><br/>
 <% end %>

 <%= submit_tag 'Save',:class => "submit" %>

```

\<% end %\>

My problem is that when the form submits, it looks for the client-  
permalink action instead of the update action.

Relevant route:

map.namespace :mynamespace do | mynamespace |  
mynamespace.resources :mycontroller  
end

Models:  
Client:  
has\_many :titles, :dependent =\> :destroy  
has\_many :text\_htmls, :dependent =\> :destroy  
Title:  
belongs\_to :page  
belongs\_to :client  
TextHtml

belongs\_to :page  
belongs\_to :client

Any ideas gratefully received,

Many thanks,

Mike

---

<div class="post-metadata">

**Author:** ![mikej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a9a28c/32.png) [@mikej](https://www.ruby-forum.com/u/mikej)\
**Post date:** [August 14, 2008, 4:45pm UTC](https://www.ruby-forum.com/t/problem-routing-form-for-to-update-action/196783/2 "2008-08-14T16:45:56Z")

</div>

I think I need the namespace in the form somehow…

---

<div class="post-metadata">

**Author:** ![mikej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a9a28c/32.png) [@mikej](https://www.ruby-forum.com/u/mikej)\
**Post date:** [August 14, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/problem-routing-form-for-to-update-action/196783/3 "2008-08-14T17:32:14Z")

</div>

Sorted. This is how if anyone cares:

\<% form\_for([:namespace,:somename], :url =\> { :action =\> :update ,:id  
=\> @client.permalink}) do |form| %\>

Controller:

def update  
@client = Client.find\_by\_permalink(params[:id])  
@title = Title.find(params[:title][:id] )  
@text\_html = TextHtml.find(params[:text\_html][:id] )

```
 if @title.update_attributes(params[:title]) &&

```

@text\_html.update\_attributes(params[:text\_html])  
flash[:notice] = ‘successfully updated.’  
redirect\_to blah  
else  
redirect\_to blee  
end  
end

Mike
