Hi everyone, I have a problem. I want to display a different select box wether the current user is an admin or an user. So I thought I could do this in my view where my form is displayed : <p class="form-input"> <%= f.label(:role_id, ''Role:'') %> <% if (current_user.admin?) then collection_select(:user, :role_id, Role.find(:all, :order => "name desc"), :id, :name) else # Here I would code an another collection_select end %> </p> But It doesn''t work. Nothing is displayed! Could you help me? Thanks! -- 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 Feb 17, 2009, at 5:52 PM, Guillaume Loader wrote:> > Hi everyone, > > I have a problem. I want to display a different select box wether the > current user is an admin or an user. > > So I thought I could do this in my view where my form is displayed : > > <p class="form-input"> > <%= f.label(:role_id, ''Role:'') %> > <%<% ^ if you want output, you generally need <%= (if you get to the point that you know to generate output from <% %>, then you will KNOW when to use them) -Rob> > if (current_user.admin?) > then collection_select(:user, :role_id, Role.find(:all, :order => > "name desc"), :id, :name) > else # Here I would code an another collection_select > end > %> > </p> > > > > But It doesn''t work. Nothing is displayed! > Could you help me? > > Thanks! > -- > 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn wrote:> On Feb 17, 2009, at 5:52 PM, Guillaume Loader wrote: > >> <% > <%> ^ > if you want output, you generally need <%= (if you get to the point > that you know to generate output from <% %>, then you will KNOW when > to use them) > > -RobI did this : <% if(current_user.admin?) then %> <%= collection_select(:user, :role_id, Role.find(:all, :order => "name desc"), :id, :name) %> <% end %> And now it displays something. Thx! -- 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 -~----------~----~----~----~------~----~------~--~---
I would do 2 things to try to fix your problem if I were you: 1. Make sure you know the type of user you have when you get the request for the page 2. Put the logic of generating the data in the controller, then use an instance variable to display the values and forget the ''if then else'' logic in the view. Your view will be much easier to read and modify. My guess is that the problem you have is that you don''t have a current_user type value (or not the one you believe you have) by the time your code runs. Pepe On Feb 17, 5:52 pm, Guillaume Loader <rails-mailing-l...@andreas- s.net> wrote:> Hi everyone, > > I have a problem. I want to display a different select box wether the > current user is an admin or an user. > > So I thought I could do this in my view where my form is displayed : > > <p class="form-input"> > <%= f.label(:role_id, ''Role:'') %> > <% > if (current_user.admin?) > then collection_select(:user, :role_id, Role.find(:all, :order => > "name desc"), :id, :name) > else # Here I would code an another collection_select > end > %> > </p> > > But It doesn''t work. Nothing is displayed! > Could you help me? > > Thanks! > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---