def test if request.post? render :text => "post" else render :text => "other" end end
when i post with a form to this page - goes into else branch, when trying to output request.post? - it's false
def test if request.post? render :text => "post" else render :text => "other" end end
when i post with a form to this page - goes into else branch, when trying to output request.post? - it's false
Are you sure you're not actually doing a PUT via hidden form fields?
It works fine for me. Here is my code:
<form method="post" action="/pages/test"> <div><input type="text" name="email" value="enter email"/></div> <div><button type="submit" name="submit">Submit</button></div> </form>
Hassan Schroeder wrote in post #1017170:
render :text => request.method # --> 'POST'
and yet render :text => request.post? # --> false
rails 3.0.9
Yes, it is a put via hidden field,
but how did a hidden field got there in a first place??
art wrote in post #1017184:
Yes, it is a put via hidden field,
but how did a hidden field got there in a first place??
Post the code that creates your form.
art wrote in post #1017180:
render :text => request.method # --> 'POST'
and yet render :text => request.post? # --> false
rails 3.0.9
Okay. Web browser can't really send PUT or DELETE requests. So rails fakes it by putting a hidden form field on the page with a value of 'put' or 'delete'. Then rails checks for that form field. I guess request.method returns the actual type of the request that the browser sent--not the type that rails fakes.