0

我有一个有时会工作有时不工作的表格,除了重新启动 rails 应用程序之外,我无法弄清楚时间之间发生了什么变化。目前它不工作。

我的路由文件中有这些条目:

constraints :subdomain => 'my' do
  namespace 'my', path: nil do
    namespace 'author' do
      resources :test_author do
        resources :steps_author
        [...]
      end
    end
  end
end

我在这里感兴趣的特定路线从rake routes

my_author_test_author_steps_author GET        /author/test_author/:test_author_id/steps_author/:id(.:format)   my/author/steps_author#show {:subdomain=>"my"}
                                   PUT        /author/test_author/:test_author_id/steps_author/:id(.:format)   my/author/steps_author#update {:subdomain=>"my"}
                                   DELETE     /author/test_author/:test_author_id/steps_author/:id(.:format)   my/author/steps_author#destroy {:subdomain=>"my"}

我的表单打开看起来像这样(使用简单的表单和引导程序):

<%= simple_form_for @step, :url => my_author_test_author_steps_author_path(@step), :html => { :class => 'form-horizontal' } do |f| %>

任何人都可以对正在发生的事情有所了解吗?

更新

根据 juanpastas 的帮助,表单似乎正确呈现,但是 Rails 将请求解释为 POST 而不是 PUT。虽然对于我的生活,我无法弄清楚为什么。

4

1 回答 1

0

You need to pass complete params in route

<%= simple_form_for @step, 
  :url => my_author_test_author_steps_author_path(author, @step),
  :html => { :class => 'form-horizontal' } do |f| %>

After reading your title I see you should be making POST to /author/test_author/24/steps_author/ without the last number. What about:

<% url = !@step.persisted? ? '/author/test_author/24/steps_author/' : my_author_test_author_steps_author_path(author, @step) %>
<%= simple_form_for @step,
  :url => url,
  :html => { :class => 'form-horizontal' } do |f| %>

I have harcoded route because I am not sure about your route helper name. You can run rake routes to find that helper.

于 2013-05-04T12:40:34.653 回答