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?

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 Cheung wrote:

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 Nantz 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

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.

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