Hello,
I''m writing an application that has a user registration functionality,
the
sign up form has a field that is called ''card'', here the user
is supposed to
enter a valid PIN code. PIN codes are stored in a table called Cards, each
card has a PIN and a serial number. If the PIN is correct and available in
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
clear
to me, this is one of them. My problem is with the PIN code validation as
described below:
#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: User.rb
has_many :cards
def self.available_pin?(card)
Card.find_by_pin(card) ? true : false
end
#Controller: users_controller.rb
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
When I try the registration I always get the flash message that says:
''PIN
is wrong'' even when I try an available PIN.
Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---