Guest User

Untitled

a guest
Apr 25th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Hi, I have a problem passing a params value from a form to the model, seems that the value arrives as null !
  2.  
  3. #User should provide a valid PIN code in the 'card' field
  4. #PIN codes are stored in a table called Cards (each card has a PIN and a Serial number)
  5. #The entered pin code should be verified against the pin codes stored in the Cards table, if not available #registration should fail.
  6.  
  7.  
  8. #Viewer
  9.  
  10. <h2>Signup</h2>
  11. <%= error_messages_for :user %>
  12. <% form_for :user, :url => users_path do |f| -%>
  13. <p>Username:<br /><%= f.text_field :username, :size => 25 %></p>
  14. <p>Email:<br /><%= f.text_field :email, :size => 25 %></p>
  15. <p>Password:<br /><%= f.password_field :password, :size => 25 %></p>
  16. <p>Password Confirmation:<br />
  17. <%= f.password_field :password_confirmation, :size => 25 %></p>
  18. <p>Mobile Number:<br /> <%= f.text_field :mobile_number, :size => 13%></p>
  19. <p>Pin Code:<br /> <%= f.text_field :card, :size => 13%></p>
  20.  
  21. <%= submit_tag 'Sign Up' %>
  22. <% end -%>
  23.  
  24. #Model
  25.  
  26. def self.available_pin?(card)
  27. Card.find_by_pin(card) ? true : false
  28. end
  29.  
  30. #Controller
  31.  
  32. def create
  33. if User.available_pin?(params[:card])
  34.  
  35. @user = User.new(params[:user])
  36. if @user.save
  37. self.logged_in_user = @user
  38. flash[:notice] = "Your account has been created."
  39. redirect_to messages_url
  40. else
  41. render :action => 'new'
  42. end
  43. else
  44. flash[:notice] = "PIN is wrong"
  45.  
  46. end
  47. end
Add Comment
Please, Sign In to add comment