0
votes

why when im trying to send this three params(recipients_emails) I get error:

ArgumentError in FreeRegistrationCouponsController#send

wrong number of arguments (2 for 0) Rails.root: /Users/regedarek/code/wifiname

Application Trace | Framework Trace | Full Trace app/controllers/free_registration_coupons_controller.rbin `send'

What Im doing wrong?

<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
2

2 Answers

1
votes

Don't call your action send - you're overwriting a core ruby method. Rails is trying to call this core ruby method, but ends up calling your method instead, which has a different signature.

Rails should probably be using __send__ so that you are free to use send for your own purposes, but there's not much you can do about that right now.

0
votes

Try changing your form to read like this:

<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>

I believe the issue is that your form_tag isn't expecting the arguments the way you've included them.