0

I have a Usetable contains username and password fields and inserted one value to that table

username:admin password:text In view file contains text boxes for username and password and a login button as follows.

<%= form_tag(:action =>"login", :method => "post", :id=>"frm") do %>

User Name:<%= text_field_tag(:username) %>
Password:<%= text_field_tag(:password) %>
<%= button_to("login ", :class=>"btn") %>
<% end %>

if the enterd username and password is same as the data present in the usertable redirct to home page other wise login is not succesful

What i want is while clicking on the login button pass the username text and password text to controller execute a mysql query like select * from usertable where uername=** and password=**

I dont know how to write mysql query inside controller method.How it is possible? my controller class looks like

    class UsersController < ApplicationController

      def home
        @username=params[:username]
        @password=params[:password]

   # here i have to write that query.#


render :action => :home
  end
end

Iam using rails 3

1
  • As a side comment you should not be storing plain passwords in the DB but I'm sure you know that. Commented May 8, 2013 at 16:07

1 Answer 1

2

Try this @user = User.where(:username => params[:username], :password => params[:password])

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

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.