samedi 28 février 2015

Ruby On Rails Signup: Submitting invalid signup twice with selected "type" radio button

I am working through Mhartl's Ruby on Rails Tutorial on the user signup portion. I am trying to implement Single Table Inheritance, which I did by adding a type column to my BaseUser model.


On my form, I added two radio buttons for the user to specify his desired account type: Property Holder, or Service Provider.


If the user checks off one of the boxes, but makes a mistake in any of the other columns, the page will re-render. If he tries to submit again, I get the following error:



param is missing or the value is empty: base_user


I think the reason that this is happening is because, my controller is sending a post request as a BaseUser the first time, but is sending a post request as a PropertyHolder the second time and sends "type" twice in the second request. Here is the relevant server log:



"property_holder"=>{"name"=>"",
"email"=>"",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]",
"type"=>"PropertyHolder"},
"commit"=>"Create my account",
"type"=>"PropertyHolder"}


Am I correct in my understanding of this problem? How should I go about fixing this?


First Time



Started POST "/base_users" for 127.0.0.1 at 2015-02-28 15:38:58 -0800
Processing by BaseUsersController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"+e5APfbWVfLCeqh1/n/05u49b+rKdGD1JJ9Vwga/y5T9uspUqmlCOioeCNCgs8x1A3RhJio+noxUjwYBG/jBUQ==",
"base_user"=>{"name"=>"",
"email"=>"",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]",
"type"=>"ServiceProvider"},
"commit"=>"Create my account"}

(0.1ms) begin transaction BaseUser Exists (0.2ms) SELECT 1 AS one FROM "base_users" WHERE LOWER("base_users"."email") = LOWER('') LIMIT 1
(0.1ms) rollback transaction
Rendered shared/_error_messages.html.erb (5.1ms)
Rendered base_users/new.html.erb within layouts/application (9.0ms)
Completed 200 OK in 110ms (Views: 92.5ms | ActiveRecord: 0.3ms)


Second Time



Started POST "/property_holders" for 127.0.0.1 at 2015-02-28 14:59:19 -0800
Processing by BaseUsersController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"VABbJX6ubQM885FNbX5Zip9MFXmTWEb3XyKzwOYbkMZQVNFMIhF6y9SXMegzsmEZcgUbtXMSuI4vMuAD+1yaAw==",
"property_holder"=>{"name"=>"",
"email"=>"",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]",
"type"=>"PropertyHolder"},
"commit"=>"Create my account",
"type"=>"PropertyHolder"}

Completed 400 Bad Request in 1ms


ActionController::ParameterMissing (param is missing or the value is empty: base_user):
app/controllers/base_users_controller.rb:28:in `user_params'
app/controllers/base_users_controller.rb:15:in `create

Aucun commentaire:

Enregistrer un commentaire