0

I am trying to define a method send in my controller:

class InvoicesController < ApplicationController

  def send
  end

end

However, I am getting an error wrong number of arguments (2 for 0) when I do this.

So I assume that send is a reserved word in Rails?

What could be a possible workaround for defining a send method in my controller anyway.

Thanks for any ideas.

3
  • 3
    send is a built-in method in ruby. Choose another name. send_invoice, for example. Or create, if you want to be RESTful. Commented Sep 1, 2014 at 17:55
  • @SergioTulentsev +1 teachmetocode.com/articles/… Commented Sep 1, 2014 at 17:56
  • What exactly is the stacktrace for the error? Commented Sep 1, 2014 at 18:20

3 Answers 3

2

You cannot call a method 'send' in ruby. Send is an Object method

send(*args) public

Invokes the method identified by symbol, passing it any arguments specified. You can use send if the name send clashes with an existing method in obj.

Send method

Sign up to request clarification or add additional context in comments.

1 Comment

It is not a reserved word.
0

The reason you can't have a send method in a controller is that send is already a method on the ruby Object class.

However, coming at the question from a slightly different angle, the main reason I can see to have a specific name for a method in this case is to get that name in the routing so that you can have, e.g.: http://localhost:3000/invoices/send or for a RESTful resource /invoices/123/send.

In which case you could call the method whatever you like and add a route named send to point at your method.

So, in your controller:

class InvoicesController < ApplicationController

  def send_invoice
    ...
  end

end

Then in config/routes.rb:

get 'invoices/send', to: 'invoices#send_invoice'

Or for an invoices resource:

resources :invoices do
  member :send, to: :send_invoice
end

Comments

0

I would consider calling it post or deliver instead

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.