# Id in form\_tag for update

**URL:** <https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742>\
**Category:** Rails\
**Created:** [September 16, 2008, 7:04pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742 "2008-09-16T19:04:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 16, 2008, 7:04pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/1 "2008-09-16T19:04:23Z")

</div>

I get an error saying Rails can’t find the post because I don’t have an  
id when doing the update. I have:

\<% form\_tag ‘/meetings/update’, :id =\> @calendar.id, :onsubmit =\>  
‘return ValidateMeeting()’ do %\>

Is this wrong?

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 16, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/2 "2008-09-16T21:48:50Z")

</div>

On 16 Sep 2008, at 18:04, Pål Bergström wrote:

> I get an error saying Rails can’t find the post because I don’t have  
> an  
> id when doing the update. I have:
> 
> \<% form\_tag ‘/meetings/update’, :id =\> @calendar.id, :onsubmit =\>  
> ‘return ValidateMeeting()’ do %\>
> 
> Is this wrong?  
> Yes 🙂

Either you provide a url or you provide a hash of routing options (eg  
id, action), not a mix of both

Fred

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 16, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/3 "2008-09-16T22:26:22Z")

</div>

Frederick C. wrote:

> On 16 Sep 2008, at 18:04, Pï¿½l Bergstrï¿½m wrote:

> Yes 🙂
> 
> Either you provide a url or you provide a hash of routing options (eg  
> id, action), not a mix of both
> 
> Fred

Not exactly sure what you mean, but I guess I’ll figure that out. Rails  
form-tags are a bit confusing.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 16, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/4 "2008-09-16T22:37:16Z")

</div>

PÃ¥l BergstrÃ¶m wrote:

> I get an error saying Rails can’t find the post because I don’t have an  
> id when doing the update. I have:
> 
> \<% form\_tag ‘/meetings/update’, :id =\> @calendar.id, :onsubmit =\>  
> ‘return ValidateMeeting()’ do %\>
> 
> Is this wrong?

Have you tried

\<% form\_tag :action =\> ‘update’, :controller =\> ‘meetings’, :id =\>  
@calendar.id, :onsubmit =\> ‘return ValidateMeeting()’ do %\>

That should call the action and the controller that you want.

-S

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 17, 2008, 8:23am UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/5 "2008-09-17T08:23:52Z")

</div>

Shandy N. wrote:

> PÃ¥l BergstrÃ¶m wrote:

> Have you tried
> 
> \<% form\_tag :action =\> ‘update’, :controller =\> ‘meetings’, :id =\>  
> @calendar.id, :onsubmit =\> ‘return ValidateMeeting()’ do %\>
> 
> That should call the action and the controller that you want.
> 
> -S

Will that not give the same form-tag? It might be that I confuse things  
here. This and mine will give the form-tag and id. I thought that id was  
the params[:id], but I guess it’s not. It’s just a regular id. I thought  
a :id in a rails-form would send it as the params[:id].

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 17, 2008, 3:08pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/6 "2008-09-17T15:08:37Z")

</div>

- the view you want to edit should be… views/calendars/  
edit.html.erb

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 17, 2008, 3:18pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/7 "2008-09-17T15:18:33Z")

</div>

Dave S wrote:

> Do you have any routes setup? Why are you updating a “calendar” via  
> the “meetings” controller? This update method should be done via a  
> “calendars” controller, with the following;
> 
> routes.rb
> 
> map.resources :calendars
> 
> views/calendars/update
> 
> \<% form\_for(@calendar) do |f| %\>  
> \<%= f.label :your\_field\_name %\>  
> \<%= f.text\_field :your\_field\_name %\>  
> \<% end %\>
> 
> This will map everything for you properly.

I don’t use routes. I don’t see the point in my application. Well  
actually, I’m not that familiar with it, as I still have to understand  
the reason for using it. I can understand it in a very straightforward  
solution, like a GUI to the db, but often it becomes more complex than  
that. But maybe I’m wrong.

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 17, 2008, 3:06pm UTC](https://www.ruby-forum.com/t/id-in-form-tag-for-update/148742/8 "2008-09-17T15:06:15Z")

</div>

Do you have any routes setup? Why are you updating a “calendar” via  
the “meetings” controller? This update method should be done via a  
“calendars” controller, with the following;

routes.rb

map.resources :calendars

views/calendars/update

\<% form\_for(@calendar) do |f| %\>  
\<%= f.label :your\_field\_name %\>  
\<%= f.text\_field :your\_field\_name %\>  
\<% end %\>

This will map everything for you properly.
