Id in form_tag for update

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?

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 :slight_smile:

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

Fred

Frederick C. wrote:

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

Yes :slight_smile:

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.

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

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].

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

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.

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.