can you use a case statement in the view.
i get a _erbout.concat "\n" error.
can someone please show the syntax on this.
can you use a case statement in the view.
i get a _erbout.concat "\n" error.
can someone please show the syntax on this.
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
anyone?
How do you use a CASE in the view?
OhMyRuby wrote:
case my_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 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!
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.
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.
OhMyRuby wrote:
yes, sorry
You _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!