I’m writing an application that has a user registration functionality,
sign up form has a field that is called ‘card’, here the user is
enter a valid PIN code. PIN codes are stored in a table called Cards,
card has a PIN and a serial number. If the PIN is correct and available
the Cards table registration will be completed successfully, else
registration will fail.
I’m relatively new to rails and there still some concepts that are not
to me, this is one of them. My problem is with the PIN code validation
Signup<%= error_messages_for :user %> <% form_for :user, :url => users_path do |f| -%>
<%= f.text_field :username, :size => 25 %>
<%= f.text_field :email, :size => 25 %>
<%= f.password_field :password, :size => 25 %>
<%= f.password_field :password_confirmation, :size => 25 %>
<%= f.text_field :mobile_number, :size => 13%>
<%= f.text_field :card, :size => 13%>
<%= submit_tag ‘Sign Up’ %>
<% end -%>
Card.find_by_pin(card) ? true : false
@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
When I try the registration I always get the flash message that says:
is wrong’ even when I try an available PIN.
Thanks in advance.