Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hi, I have a problem passing a params value from a form to the model, seems that the value arrives as null !
- #User should provide a valid PIN code in the 'card' field
- #PIN codes are stored in a table called Cards (each card has a PIN and a Serial number)
- #The entered pin code should be verified against the pin codes stored in the Cards table, if not available #registration should fail.
- #Viewer
- <h2>Signup</h2>
- <%= error_messages_for :user %>
- <% form_for :user, :url => users_path do |f| -%>
- <p>Username:<br /><%= f.text_field :username, :size => 25 %></p>
- <p>Email:<br /><%= f.text_field :email, :size => 25 %></p>
- <p>Password:<br /><%= f.password_field :password, :size => 25 %></p>
- <p>Password Confirmation:<br />
- <%= f.password_field :password_confirmation, :size => 25 %></p>
- <p>Mobile Number:<br /> <%= f.text_field :mobile_number, :size => 13%></p>
- <p>Pin Code:<br /> <%= f.text_field :card, :size => 13%></p>
- <%= submit_tag 'Sign Up' %>
- <% end -%>
- #Model
- def self.available_pin?(card)
- Card.find_by_pin(card) ? true : false
- end
- #Controller
- def create
- if User.available_pin?(params[:card])
- @user = User.new(params[:user])
- if @user.save
- self.logged_in_user = @user
- flash[:notice] = "Your account has been created."
- redirect_to messages_url
- else
- render :action => 'new'
- end
- else
- flash[:notice] = "PIN is wrong"
- end
- end
Add Comment
Please, Sign In to add comment