On 2 August 2010 15:34, Dave Aronson <[email protected]> wrote:
> On Sun, Aug 1, 2010 at 06:52, Michael Pavling <[email protected]> wrote:
>> You can use conditional checking inline, with "normal" 'if...else' blocks:
>
> Though your approach will work, this looks to me like it's probably
> logic that more properly belongs in the controller than the view.
> IMHO using something like:
>
> if @my_object.active?
> �...@activated_msg = 'This is active'
> else
> �...@activated_msg = 'You need to activate this one'
> end  # you did mean end for the 2nd else above, yes?

I know that you and Marnen have covered this, so I won't go over it
too much, but I would add my voice to the "it should NOT be in the
controller" camp. I may reuse the same views from several controller
actions, and I don't want to have to duplicate the variable-setting in
lots of places.

The "I don't want view text in my controllers" has already been covered.

I also don't see the value in setting instance variables to store
values that are accessible on the model that's being passed to the
view.

Also, the conditional block might be being operated on an element of a
collection, and I *really* don't want to iterate all my foos to see
whether each has bar set true or not (I'm sorry for using "active"
earlier, as it seemed to get the focus of the consideration), and then
store that result in another hash...
etc.


> (BTW, note the single quotes; I haven't verified it myself, but heard
> that they are at least marginally faster for constant strings (i.e.,
> where you *can* use them), since the system won't even *try* to look
> for vars that need to be interpolated.  Makes sense to me.)

They are, to all reports, marginally faster, but I still use double
quotes everywhere for ease and consistency . It strikes me as
premature optimisation to default to single quotes for the minuscule
time advantage (and I rarely set strings to variables anyway;
generally following the "extract variable" refactoring pattern instead
and call a method to return them - even slower! But easier to maintain
;-)

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to