title: Check row exist or not in Ruby on Rails
body: <p>I am new to Ruby on Rails and I have basic knowledge of mysql. I am using MySQL db. My question is -- how to check if a row is exists or not in a table. I have tried this code but it's not going straight to the <code>else</code> block, not the <code>if</code> block:</p>
  
  <pre><code>@tasks = User.find_by("user_name = ? AND password = ?", params[:user_name], params[:password])
  if @tasks
    redirect_to action: 'index', status: 302
  else
    redirect_to action: 'detail', status: 302
  end
  </code></pre>