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 <label for="user_login">Username:</label> <%= text_field("login", "username", :size=>"20" ) %> <label for="user_password">Password:</label> <%= password_field("login", "password",:size=>"22" ) %> <label for="user_login">Role:</label> #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... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Jan 2009, at 11:52, Tony Puthenveettil 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 http://guides.rails.info/form_helpers.html Fred> Appreciate your prompt reply... > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 27 Jan 2009, at 11:52, Tony Puthenveettil 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 > http://guides.rails.info/form_helpers.html > > FredThanks a lot Frederick... I was looking for a simple logic. However it must work. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---