Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7498827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:36:40+00:00 2026-05-29T19:36:40+00:00

I have a form in which a user (‘member’) submits a 4-digit pin, which

  • 0

I have a form in which a user (‘member’) submits a 4-digit pin, which is then saved to a session variable called :submitted_pin. For some reason, the quick if/else statement isn’t working properly, and I am assuming it is a silly mistake on my part, but if your willing to take a look I would really appreciate it!

View

<%= form_for :member_pin, :url => { :action => "verify_pin", :id => member.id } do |f| %>`
  <%= f.label :pin %>
  <%= f.text_field :pin %>
<%= f.submit 'Submit' %>

Controller

Before Filter

before_filter :validate_pin, :only => :show

Action (POST Route)

def verify_pin
  @member = Member.find(params[:id])

  session[:submitted_pin] = params[:member_pin][:pin]
  redirect_to @member
end

Filter

def validate_pin
  @member = Member.find(params[:id])
  @member_pin = @member.pin

  if session[:submitted_pin] == @member_pin
    render @member
  else
    redirect_to '/'
  end
end

And the result of all of this is a redirect to my root_url no matter what, even if the Pin entered does match the pin in the database for that user. Help! Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:36:43+00:00Added an answer on May 29, 2026 at 7:36 pm

    Based on the results of the raise we talked about in the comments, it sounds like there’s a class mismatch. The easiest way to fix (and, IMHO, the easiest to read) would be to adjust your validator code as follows:

    if session[:submitted_pin].to_i == @member_pin.to_i
      render @member
    else
      redirect_to '/'
    end
    

    If there’s any chance that session[:submitted_pin] would be nil, you can use session[:submitted_pin].try(:to_i); that’ll return nil if the variable is not set and prevent an error from getting thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET web form which I am adding a variable number User
I have a form in which user input some details and then click a
I have a form which submits user first and last name using POST signin.html
i have one form which collect user information Name Age CV and then i
I have a form in which the user can choose a component type from
I have a form in which the user selects a few items to display
I have got a form which a user can use to create a new
I have a form which takes both the user details and an image uploaded
I have a form which have many check boxes in it. User will check
I have a web form where I have a textbox in which the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.