Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. The form in the view: (edit_profile.rhtml)
  2.  
  3. <% form_for :user do |f| -%>
  4. <p> Email Address: </p>
  5. <%= f.text_field :email %>
  6.  
  7. <p> City: </p>
  8. <%= f.text_field :city %>
  9.  
  10. <p> Country: </p>
  11. <%= f.text_field :country %>
  12.  
  13. <p> Postal Code: </p>
  14. <%= f.text_field :postal %>
  15.  
  16. <p> Username: </p>
  17. <%= f.text_field :login %>
  18.  
  19. <p> Password: </p>
  20. <%= f.password_field :password %>
  21.  
  22. <p> Re-enter Password </p>
  23. <%= f.password_field :password_confirmation %>
  24.  
  25. <p> Select Photo: (175x175) </p>
  26. <%= file_column_field "user", :icon %>
  27. <p> First Name: </p>
  28. <%= f.text_field :first_name %>
  29. <p> Last Name: </p>
  30. <%= f.text_field :last_name %>
  31. <p> Comments: </p>
  32. <%= f.text_area(:comments, "cols" => 35, "rows" => 6) %>
  33.  
  34. <%= image_submit_tag '/images/update-now-button.jpg', :class => "register-now", :border => "0" %>
  35.  
  36.  
  37.  
  38. My controller: (account_controller.rb)
  39.  
  40.  
  41.  
  42. def edit_profile
  43. @user = User.find(params[:id])
  44. end
  45.  
  46. def update_profile
  47. @user = User.find(params[:id])
  48. if @user.update_attributes(params[:user])
  49. flash[:notice] = 'Profile was successfully updated.'
  50. redirect_to :controller => 'user', :action => 'home', :id => @user
  51. else
  52. render :action => 'edit_profile'
  53. end
  54. end
  55.  
  56.  
  57.  
  58. Logs:
  59.  
  60.  
  61.  
  62. Parameters: {"user"=>{"city"=>"", "postal"=>"", "comments"=>"sdfasdfasdf", "icon"=>"", "password_confirmation"=>"", "country"=>"", "icon_temp"=>"", "first_name"=>"test", "login"=>"test", "password"=>"", "last_name"=>"test", "email"=>"test@test.com"}, "x"=>"42", "y"=>"18", "action"=>"edit_profile", "id"=>"1", "controller"=>"account"}
  63.  
  64.  
  65.  
  66. @users.inspect reports:
  67.  
  68.  
  69.  
  70. {"salt"=>"59c214e787404998ee05c27ed3b142d2cc1d4d41", "postal"=>nil, "city"=>nil, "updated_at"=>Wed Jan 31 13:35:20 0700 2007, "crypted_password"=>"990d1e6b8cc925ce4687c3e4e4986105d7a1476e", "comments"=>nil, "icon"=>nil, "remember_token_expires_at"=>nil, "country"=>nil, "id"=>1, "gender"=>"male", "remember_token"=>nil, "first_name"=>"test", "login"=>"test", "last_name"=>"test", "birth"=>1975, "email"=>"test@test.com", "created_at"=>Wed Jan 31 13:35:04 0700 2007}
  71.  
  72.  
  73.  
  74. params[:user].inspect reports:
  75.  
  76.  
  77.  
  78. {"city"=>"", "postal"=>"", "comments"=>"sdfasdfasdf", "icon"=>"", "password_confirmation"=>"", "country"=>"", "icon_temp"=>"", "first_name"=>"test", "login"=>"test", "password"=>"", "last_name"=>"test", "email"=>"test@test.com"}
  79.  
  80.  
  81.  
  82.  
  83. However, my controller code "if @user.update_attributes(params[:user])" is not updating the database.. Do these hashes have to be intentical? any idea what im missing?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement