# Login form\_tag with select\_tag option

**URL:** <https://www.ruby-forum.com/t/login-form-tag-with-select-tag-option/158736>\
**Category:** Rails\
**Created:** [January 27, 2009, 12:52pm UTC](https://www.ruby-forum.com/t/login-form-tag-with-select-tag-option/158736 "2009-01-27T12:52:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 27, 2009, 12:52pm UTC](https://www.ruby-forum.com/t/login-form-tag-with-select-tag-option/158736/1 "2009-01-27T12:52:35Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 27, 2009, 3:36pm UTC](https://www.ruby-forum.com/t/login-form-tag-with-select-tag-option/158736/2 "2009-01-27T15:36:46Z")

</div>

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](http://guides.rails.info/form_helpers.html)**
>
> Ruby on Rails,Rails Tutorial,Ruby Basics,Rails 4,Bar Rails,Rail

Fred

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 28, 2009, 4:49am UTC](https://www.ruby-forum.com/t/login-form-tag-with-select-tag-option/158736/3 "2009-01-28T04:49:35Z")

</div>

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](http://guides.rails.info/form_helpers.html)
> 
> Fred

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