开发者

rails admin edit view path routes

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.

Than开发者_StackOverflow社区ks for the help!!


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.


This works:

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

Seems verbose though. Any better ideas?


Try

- form_for :subscription, @subscription do |f|

We're using formtastic here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜