Is it better to create 2 actions, 1 for get and 1 for post, or can you just merge the 2?
Is it possible to have a controller action do both the GET and POST?
i.e. the GET shows a form, and the POST t开发者_开发技巧akes the forms values and saves to the db.
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.
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
精彩评论