Reputation: 10207
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.
Upvotes: 0
Views: 477
Reputation: 34774
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
Upvotes: 0
Reputation: 386
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.
Upvotes: 2