Is it acceptable keep logic in view templates (in MVC terms and Rails specifically)? Is there any way to avoid something like this?
<% if current_user %>
Welcome, <%= current_user.name %>.
<%= link_to "Sign Out", signout_path %>
<% else %>
<%= link_to "Sign in with Twitter", "/auth/twitter" %>
<% end %>
Or am I inventing a "bicycle" and the upper stuff goes well?
Comes down to preference of course. I would say that the above is pretty acceptable. Simple conditions and loops are pretty standard in a view. I would say the things to avoid would be assigning variables, hitting models for data you haven't already gathered, etc.
If you don't want anything like tha in there, you can always build helpers. This kind of thing has to be somewhere.
edit:
a good rule of thumb is "does this code directly relate to the presentation?" I would say the answer regarding your above case is yes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With