views:

26

answers:

3

I've got an admin section setup, but am having trouble getting the "update" route to work.

Getting error when hitting "update" via the edit view:
"No action responded to 2."

For some reason the route is responding to the :id as the :action.

Parameters:
Parameters: {"commit"=>"Update", "action"=>"2", "_method"=>"put", "admin"=>{"ended_at(1i)"=>"2010", "ended_at(2i)"=>"8", "ended_at(3i)"=>"22"}, "id"=>"edit", "controller"=>"admin/subscriptions"}

The edit view uri:
/admin/subscriptions/2/edit

Edit view:

<% form_for :admin, @subscription, :html => {:method => :put} do |f| %>
  <p>
    <%= f.label :ended_at %><br />
    <%= f.date_select :ended_at %>
  </p>
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>

Route:

  map.namespace :admin do |admin|
    admin.resources :subscriptions
  end

I assume I need to do something differently in the form_for method or maybe the routes, but everything I've tried isn't working.

Thanks for the help!!

A: 

This works:

<% form_for :admin, @subscription, :html => {:method => :put}, :url => { :action => "update" } do |f| %>

Seems verbose though. Any better ideas?

bandhunt
Check out my answer: http://stackoverflow.com/questions/3543673/rails-admin-edit-view-path-routes/3543798#3543798
Ryan Bigg
A: 

Try

- form_for :subscription, @subscription do |f|

We're using formtastic here.

Tass
The `:subscription` is redundant? He's also namespacing the Subscription resource, so he'll need to use the Array form.
Ryan Bigg
A: 

It should be this:

<% form_for [:admin, @subscription] do |f| %>

By putting :admin and @subscription in square-brackets, this makes it into an array which is passed as the first argument to form_for. The benefit of this is if @subscription is a pre-existing record (as-in, one found by find, not created with new) then Rails will know to set the form method to PUT.

Ryan Bigg
hmm. thanks! that works for another controller. for this one i'm getting a "show" action when doing that. not a big issue as i'm able to force the action, but it's not clean ;)
bandhunt