Login form_tag with select_tag option

Hi all,
In the application i develop, a sophisticated login system is required.
Being a newbie in Ruby, i’m not comfortable with the select tag in the
form tag.
My requirement:
2 tables - User(LoginName, Password, RoleId…) and Role(RoleId,
RoleName…)
View - RoleNames to be loaded in the drop down box and On submit, RoleId
to be passed to controller for authentication.

My Code Snippet:
#Controller
if request.post? and params[:login]
@user = User.new(params[:login])
validUser = User.find(:first,:conditions => [“login_name = ? and
password = ? and role_id = ?”,@user.logname, @user.password,
@user.roleid])
if validUser
@role = Role.find(:first, :conditions => [“id = ?”,
@user.roleid])
if @role.role_name == “Admin”
session[:admin] = validUser.id
redirect_to :controller=>‘admins’, :action => ‘index’
else
session[:user] = validUser.id
redirect_to :controller=>‘projects’, :action => ‘index’
end
#View
Username:
<%= text_field(“login”, “username”, :size=>“20” ) %>
Password:
<%= password_field(“login”, “password”,:size=>“22” ) %>
Role:
#Here is the issue
<% @role = Role.find(:all, :select => “role_name”) %>
<%= select_tag(“login”, options_for_select(@role)) %>
<%# collection_select(:role, :id, @role, :id, :role_name) %>
<%= submit_tag “Login” %>

Could anybody please give me a better snippet to accomplish the same…?

Appreciate your prompt reply…

On 27 Jan 2009, at 11:52, Tony P. wrote:

Hi all,
In the application i develop, a sophisticated login system is
required.
Being a newbie in Ruby, i’m not comfortable with the select tag in the
form tag.

Could anybody please give me a better snippet to accomplish the
same…?

have a look at the (still in progress) guide on forms

Fred

Frederick C. wrote:

On 27 Jan 2009, at 11:52, Tony P. wrote:

Hi all,
In the application i develop, a sophisticated login system is
required.
Being a newbie in Ruby, i’m not comfortable with the select tag in the
form tag.

Could anybody please give me a better snippet to accomplish the
same…?

have a look at the (still in progress) guide on forms
rails.info

Fred

Thanks a lot Frederick… I was looking for a simple logic. However it
must work.