Reputation: 493
I recently looked at sample code for a controller in a rails project which included a method definition in a class without defining the name of the method like so:
def begin
redirect_to :action => :buy, :PaymentAction => params[:paymentaction]
rescue Errno::ENOENT => exception
flash[:error] = exception
redirect_to :controller => 'wppro', :action => 'exception'
end
Is this a way of defining a constructor in rails?
Upvotes: 0
Views: 194
Reputation: 177550
In this case, begin
is just the name of a method; it's unrelated to the begin
…rescue
syntax for handling exceptions (in which the begin
is sometimes optional). foo.begin
is valid syntax for calling this method as well.
Since we're inside a Rails controller, begin
is additionally the name of an action.
Constructors are defined with the initialize
instance method.
Upvotes: 4