can you use a case statement in the view. i get a _erbout.concat "\n" error. can someone please show the syntax on this. --~--~---------~--~----~------------~-------~--~----~ 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 can do this case my_variable when "1", "3" "5" ..... when "8", "9" ..... else .... end but I can not do this in the view. Am I missing something here or do I have to use nested IF in the view. Thanks On May 5, 12:47 pm, OhMyRuby <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> can you use a case statement in the view. > > i get a _erbout.concat "\n" error. > > can someone please show the syntax on this.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
anyone? On May 5, 1:03 pm, OhMyRuby <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I can do this > > case my_variable > when "1", "3" "5" > ..... > when "8", "9" > ..... > else > .... > end > > but I can not do this in the view. > Am I missing something here or do I have to use nested IF in the view. > > Thanks > > On May 5, 12:47 pm, OhMyRuby <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > can you use a case statement in the view. > > > i get a _erbout.concat "\n" error. > > > can someone please show the syntax on this.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How do you use a CASE in the view? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
OhMyRuby wrote:> case my_variable > when "1", "3" "5" > ..... > when "8", "9" > ..... > else > .... > endThat looks fine by itself. (As a style thing, why does my_variable contain strings instead of numbers?) What''s in the ... ? Is it %> <% ? If so, write what you need another way (even if eRB supports that notation). Ideally, you should move the case to a model, and call a method on that model here. Also, does the top case have a <%= before it? You must provide more details in questions, to increase the odds someone spots the actual problem! -- 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 -~----------~----~----~----~------~----~------~--~---
yes, sorry <% case my_variable %> tried <%= case my_variable %> neither one worked. i will look at the code as to having it in the model or in the controller, but i don''t think it would work. eventually i did if [ "1", "3", "8", "15"].any? { |x|.....} and got it to work. On May 5, 7:37 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> OhMyRuby wrote: > >casemy_variable > > when "1", "3" "5" > > ..... > > when "8", "9" > > ..... > > else > > .... > > end > > That looks fine by itself. (As a style thing, why does my_variable contain > strings instead of numbers?) > > What''s in the ... ? Is it %> <% ? > > If so, write what you need another way (even if eRB supports that notation). > Ideally, you should move thecaseto a model, and call a method on that model here. > > Also, does the topcasehave a <%= before it? > > You must provide more details in questions, to increase the odds someone spots > the actual problem! > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Just for reference, you use <% %> to simply evaluate the code and <%= %> when you want the evaluation rendered into the view. Depending on what you''re trying to inject into the view, you could put the case in the controller and use it to put the name of a partial in an instance variable, then use a render :partial=>@my_partial_view as an alternative. BTW, Phlip was right -- you didn''t get quick responses because there was not enough info for us to help. On May 5, 11:14 pm, OhMyRuby <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yes, sorry > > <% case my_variable %> > > tried <%= case my_variable %> > > neither one worked. > > i will look at the code as to having it in the model or in the > controller, but i don''t think it would work. > > eventually i did if [ "1", "3", "8", "15"].any? { |x|.....} > > and got it to work. > > On May 5, 7:37 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > OhMyRuby wrote: > > >casemy_variable > > > when "1", "3" "5" > > > ..... > > > when "8", "9" > > > ..... > > > else > > > .... > > > end > > > That looks fine by itself. (As a style thing, why does my_variable contain > > strings instead of numbers?) > > > What''s in the ... ? Is it %> <% ? > > > If so, write what you need another way (even if eRB supports that notation). > > Ideally, you should move thecaseto a model, and call a method on that model here. > > > Also, does the topcasehave a <%= before it? > > > You must provide more details in questions, to increase the odds someone spots > > the actual problem! > > > -- > > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
OhMyRuby wrote:> yes, sorryYou _still_ didn''t post enough code!> neither one worked.eRB can''t interpret code structured like this. I think you did this: <% case %> <% when %> <% ... %> <% when %> <% ... %> <% when %> <% ... %> <% end %> Think of eRB as a way to declare HTML inside strings delimited by %> < %. This might work: <% case when %>... <% when %>... <% when %>... <% end %> If you don''t see the difference yet, compare to an if statement! -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---