Display form and process return values with same method?

Is it sensible to use the same method in a controller to both display a
form and process its return values?

So instead of new and create methods you would just have new.

Pseudo-code:

def new
if system.post_response? then
@user = User.create(params[:user])
@user.save
else
@user = User.new
end
end

Disclaimer: system.post_response? is completly made up! Basically i
guess it should return true if params[] has something in it.

Cheers Pete.

Actual code (from a working controller):
def add
if request.get?
@payer = Payer.new
else
@payer = Payer.new(params[:payer])
if @payer.save
flash[:notice] = “Payer #{@payer.name} created”;
redirect_to :action => ‘add’
end
end
end

You could also flip the clauses and ask “if request.post?” (not made
up!)

-Rob

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs