Rails and Flash params
I'm trying to post a value to my rails website from Flash.
What I've got is a URL of http://localhost:3000/users/new
which I post to from Flash. The variable I'm sending as a POST method is score=xx
. For some reason I can't pick up the value in my rails controller in the new method: @newScore = params[:score]
. If I change the method t开发者_开发问答o a GET I can get to the value with no problem. So should I be using the params hash on a POST method?
If someone can advice I'd much appreciate it.
Are you using custom routes? Or do you just do resources :users
? Better run rake routes
. /users/new
is usually a GET, which makes sense, since you're fetching an object. The create
action is the only POST, and that maps to /users
. Doing /users/new
as a POST breaks REST.
POST data is not allowed on a GET method. Any parameters will be put on the query string in the URL. Those parameters will still show up in the params
hash.
Edit
If you're actually trying to create a user with this REST call, you need to POST to http://localhost:3000/users, not http://localhost:3000/users/new
Edit
Unfortunately I don't know enough about how flash sends POST requests to tell you why your params aren't coming accross. However, if you're trying to get to the form, you definitely need a GET to http://localhost:3000/users/new. You say that you can pick up the variable just fine when you do a GET, right? So you don't need to do a POST.
If you don't want the user to be able to edit the score, then you save the value to a variable in the controller, and when you render the view, you put that value in an non-editable element, like a disabled text box or maybe even just a label.
Edit
If you can figure out how to get your Post data across from Flash to Rails, you'll need to do a POST to users_url
, and then you can modify your create
method to send back the id of the user that was created. Then when you get that back, you can make another call to edit the user with that id, leaving the score field disabled. Best of luck.
精彩评论