Peter Piper
2006-Jan-23 10:36 UTC
[Rails] 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.
--
Posted via http://www.ruby-forum.com/.
Rob Biedenharn
2006-Jan-23 13:38 UTC
[Rails] Display form and process return values with same method?
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
At 1/23/2006 05:36 AM, you wrote:>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.
>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060123/19e87c95/attachment.html