1

My doubt is i am throwing an sql statement

@authenticates = Authenticate.find(
  :all, 
  :conditions => ["userid = ? AND password = ?", params[:text1], params[:text2]]
)

I need to put an if condition, so that if the above data exists i need to redirect to other page else display an error

How can i do this

3
  • Check the variable your set and change the location you redirect to? Commented Jul 4, 2012 at 14:59
  • 1
    Also, consider naming your parameters something actually meaningful. Commented Jul 4, 2012 at 15:00
  • 1
    btw "passwords" that are stored and retrieved like this == open access ;) Commented Jul 4, 2012 at 15:06

3 Answers 3

2

Seems that you need an authentication example. Check this.

Otherwise you just need an if condition to check if the @authenticates variable contains anything or not.

Sign up to request clarification or add additional context in comments.

Comments

1

You just want the if clause that'll make this happen? If so:

if params[:text1] && params[:text2]
  @authenticates = Authenticate.find(
    :all, 
    :conditions => ["userid = ? AND password = ?", params[:text1], params[:text2]]
  )
 else
   redirect_to page_where_the_params_are_set_path
 end

Comments

0

I need to put an if condition, so that if the above data exists i need to redirect to other page else display an error

Sorry, but your question is awkwardly worded. I would suggest rephrasing the question clearly, so that you can get the right response. I presume what you want is something like this

@authenticates = Authenticate.find(
  :all, 
  :conditions => ["userid = ? AND password = ?", params[:text1], params[:text2]]
)
if @authenticates.count < 1
  redirect_to some_action_path
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.