Is it possible to have a controller action do both the GET and POST?
i.e. the GET shows a form, and the POST takes the forms values and saves to the db.
Is it possible to have a controller action do both the GET and POST?
i.e. the GET shows a form, and the POST takes the forms values and saves to the db.
Yes it's possible. You just need check the method to call you action
def show
if request.post?
render :text => "it's a post"
elsif request.get?
render :text => "it's a get"
else
render :text => "it's another method"
end
end
As already mentioned it is possible, but I feel it is bad style. Showing a form and saving something are different actions and your code should reflect that.
If you just want to access both action via the same url you can just set up your routes accordingly. This is done differently depending on whether you use Rails 2 or Rails 3.