Is there any better way to do this? <li <%= (''class="current"'') if controller.controller_name == ''users'' && controller.action_name == ''login'' %>> -- 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 -~----------~----~----~----~------~----~------~--~---
Gi Ga wrote:> Is there any better way to do this? > > <li <%= (''class="current"'') if controller.controller_name == ''users'' && > controller.action_name == ''login'' %>>Here''s my take: <%= content_tag :li, (:class => "current" unless current_page? (:controller => ''users'', :action => ''login'')) %> I''ve not actually tried it though. Bill -- 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 -~----------~----~----~----~------~----~------~--~---
Bill Devaul wrote:> Gi Ga wrote: >> Is there any better way to do this? >> >> <li <%= (''class="current"'') if controller.controller_name == ''users'' && >> controller.action_name == ''login'' %>> > > Here''s my take: > > <%= content_tag :li, (:class => "current" unless current_page? > (:controller => ''users'', :action => ''login'')) %> > > I''ve not actually tried it though. > > BillNow that I look again, I think the "unless" needs to be "if". Bill -- 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 -~----------~----~----~----~------~----~------~--~---
<li<% if controller.controller_name == ''users'' && controller.action_name == ''login'' %> class="current"<% end %>> Probably safe syntax. I usually don''t like to print things inside of operations. Plus, with this, you won''t get any unnecessary whitespace. But, there is no right way. As long as that Ruby interpreter does it''s job and doesn''t blow up in your face! On Jan 3, 2:04 pm, Gi Ga <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Is there any better way to do this? > > <li <%= (''class="current"'') if controller.controller_name == ''users'' && > controller.action_name == ''login'' %>> > -- > 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 -~----------~----~----~----~------~----~------~--~---
> <li <%= (''class="current"'') if controller.controller_name == ''users'' && > controller.action_name == ''login'' %>>First, move "if controller.controller_name == ''users'' && controller.action_name == ''login''" into a helper and give it a name, such as login_page_class. It should return nil on the wrong page and ''current'' on the right page. Next, use content_tag to build the entire li. Then if :class => login_page_class contains the nil, the class="" itself will go away in the rendered HTML. (And put all this under test, because it''s logic that you want to keep alive as you upgrade this site!) -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
#order can be "date" or "score" or "user" @order = "date" #default @order = session[:order] if session[:order] @order = params[:order] if params[:order] orderby = "updated_on DESC" #default orderby = "score DESC" if @order == "score" orderby = "user" if @order == "user" session[:order] = @order @results = Stats.find(:all, :order => orderby, :conditions.......... -- 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 -~----------~----~----~----~------~----~------~--~---
* James Bond <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> [2009-01-25 15:07:51 +0100]:> > #order can be "date" or "score" or "user" > > @order = "date" #default > @order = session[:order] if session[:order] > @order = params[:order] if params[:order] > > orderby = "updated_on DESC" #default > orderby = "score DESC" if @order == "score" > orderby = "user" if @order == "user" > > session[:order] = @order > > @results = Stats.find(:all, :order => orderby, :conditions..........@order = params[:order] || session[:order] || ''date'' orderby = case @order when ''user'' then ''user'' when ''score'' then ''score DESC'' else ''updated_on DESC'' end my $0.02 Jan> -- > 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@googlegroups.com > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~----- jan=callcc{|jan|jan};jan.call(jan)
James Bond wrote:> #order can be "date" or "score" or "user"Don''t use @ unless you are really passing a variable to other methods in this class.> @order = "date" #default > @order = session[:order] if session[:order] > @order = params[:order] if params[:order]order = session[:order] || params[:order] || ''date'' Note I use single ''ticks'' because I don''t need the special abilities of "". That represents a very important style rule - use the simplest code you can. Think of "" as "costing more" than ''''.> orderby = "updated_on DESC" #default > orderby = "score DESC" if @order == "score" > orderby = "user" if @order == "user"orderby = order == ''date'' ? ''updated_on'' : order> session[:order] = @order > > @results = Stats.find(:all, :order => orderby, :conditions..........--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Xie Hanjian wrote:> orderby = case @order > when ''user'' then ''user'' > when ''score'' then ''score DESC'' > else ''updated_on DESC'' > endThat''s better than mine by preserving the DESC. But why the params and session themselves don''t contain the real code - ''updated_on DESC''. The View could, for example, show ''date'' to the user and set its value to ''updated_on DESC''. Then all this fun goes away! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
* Phlip <phlip2005-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> [2009-01-25 08:32:22 -0800]:> > Xie Hanjian wrote: > > > orderby = case @order > > when ''user'' then ''user'' > > when ''score'' then ''score DESC'' > > else ''updated_on DESC'' > > end > > That''s better than mine by preserving the DESC. > > But why the params and session themselves don''t contain the real code - > ''updated_on DESC''. The View could, for example, show ''date'' to the user and set > its value to ''updated_on DESC''. Then all this fun goes away!Agree. The only reason may be security - user would know your table column name ''updated_on'' if you use it directly in view. Jan> > > --~--~---------~--~----~------------~-------~--~----~ > 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 > -~----------~----~----~----~------~----~------~--~----- jan=callcc{|jan|jan};jan.call(jan)
Xie Hanjian wrote:>> But why the params and session themselves don''t contain the real code - >> ''updated_on DESC''. The View could, for example, show ''date'' to the user and set >> its value to ''updated_on DESC''. Then all this fun goes away! > > Agree. The only reason may be security - user would know your table > column name ''updated_on'' if you use it directly in view.They also might hack the params and put in a SQL injection attack. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---