0

为什么当我尝试发送这三个参数(recipients_emails)时出现错误:

FreeRegistrationCouponsController#send 中的参数错误

参数数量错误(2 代表 0) Rails.root:/Users/regedarek/code/wifiname

应用程序跟踪 | 框架跟踪 | 完整跟踪 app/controllers/free_registration_coupons_controller.rbin `send'

我做错了什么?

<div class="span6">
  <b>Give three of your friends a free registration</b>
  <%= form_tag :controller => 'free_registration_coupons', :action => "send" do %>
    <%= label_tag :recipient_email_1 %>
    <%= text_field_tag :recipient_email_1 %>
    <%= label_tag :recipient_email_2 %>
    <%= text_field_tag :recipient_email_2 %>
    <%= label_tag :recipient_email_3 %>
    <%= text_field_tag :recipient_email_3 %>
    <%= submit_tag %>
  <% end %>
</div>

class FreeRegistrationCouponsController < ApplicationController
  def send
    @sender_id = current_user.id

    binding.pry
    redirect_to root_path
  end
end

resources :free_registration_coupons do
  collection do
    get 'send'
    post 'send'
  end
end
4

2 回答 2

1

不要调用您的操作发送 - 您正在覆盖核心 ruby​​ 方法。Rails 试图调用这个核心 ruby​​ 方法,但最终却调用了你的方法,它具有不同的签名。

可能应该使用 Rails,__send__以便您可以自由地send用于自己的目的,但现在您无能为力。

于 2012-05-03T14:10:19.940 回答
0

尝试将您的表单更改为如下所示:

<div class="span6">
  <b>Give three of your friends a free registration</b>
  <%= form_tag '/free_registration_coupons/send' do %>
    <%= label_tag :recipient_email_1 %>
    <%= text_field_tag :recipient_email_1 %>
    <%= label_tag :recipient_email_2 %>
    <%= text_field_tag :recipient_email_2 %>
    <%= label_tag :recipient_email_3 %>
    <%= text_field_tag :recipient_email_3 %>
    <%= submit_tag %>
  <% end %>
</div>

我认为问题在于您的 form_tag 并不期望您包含它们的方式的论点。

于 2012-05-03T14:17:03.740 回答