未知动作,即使我使用了收藏

时间:2014-10-01 16:29:35

标签: ruby-on-rails model-view-controller routes action

Rails 2.2.3,Ruby 1.8.7

我有一个控制器表格。有很多形式......我在控制器表单上声明了methode import_cash_payments,之后我通过集合在路由中添加了它。无论如何,它给了我这个错误。

看,那是在我的forms_controller.rb中:

def import_cash_payments
      @title = "Импорт наличных оплат"
end 

这是路线:

map.resources :forms,
    :collection => {
      :import_cash_payments => :post, {...}, :export_form10 => :post
    }

另外,我有查看文件:forms / import_cash_payments.html.erb

我回忆道:(查看)

Unknown action
No action responded to show. Actions: ...(many actions)..., import_cash_payments, ...(many actions)...

这是来自控制台中的rake routes命令:

 import_cash_payments_forms POST   /forms/import_cash_payments                         {:controller=>"forms", :action=>"import_cash_payments"}

1 个答案:

答案 0 :(得分:1)

在第3和第4栏中

# config/routes.rb
. . .
resources :forms do
  collection do
    post 'import_cash_payments'
  end
end
. . .
# controllers/forms_controller.rb
class FormsController < ApplicationController
  def new
    @cash = Cash.new
  end

  def import_cash_paymenes
    @cash = Cash.new(cash_params)
    @cash.save
    . . .
  end
end

# app/views/forms/new.html.erb
<%= form_for @cash, url: 'import_cash_payments_path' do %>
. . .
<% end %>