Problem with elsif

hi!

i have a little problem, im working with permissions, so if u are a
normal user, u can only view something and admins can view,edit, delete

i pick up the level, and then i check up, if the level is right, and
then i put the options. but i dont know why, the admin can only view and
delete, i mean my code only take the last link_to

here is the code:

<%= link_to “read”, :action => “show”, :id => message.send(‘id’) %>
<%= if @level == 2
link_to “edit”, :action => “edit”, :id => message.send(‘id’)
elsif @level == 3

    #HERE IS THE PROBLEM, I BECOME ONLY THE LINK TO DESTROY, AND NOT 

BOTH.
link_to “edit”, :action => “edit”, :id => message.send(‘id’)
link_to “destroy”, :action => “destroy”, :id => message.send(‘id’)

 end

%>

ty!!

help please, im trying everything and nothing

pipogol wrote:

help please, im trying everything and nothing

…it’s a little hard to understand from what you’ve written above(and
how is @level defined?), but on a very first glance, <%= if …blah %>
isn’t a correct syntax.

instead of doing <%= if a
elsif b
else c
%>

do
<% if %><%= a %>
<% elsif %><%= b %>
<% else %><%= c %>
<% end %>

helps?

On 7/26/06, pipogol [email protected] wrote:

 end

%>

<%= link_to “read”, :action => “show”, :id => message.send(‘id’) %>
<%= if @level == 2
link_to “edit”, :action => “edit”, :id => message.send(‘id’)
elsif @level == 3
link_to(“edit”, :action => “edit”, :id => message.send(‘id’)) +
link_to(“destroy”, :action => “destroy”, :id =>
message.send(‘id’))
end
%>

or:

<%= link_to “read”, :action => “show”, :id => message.send(‘id’) %>
<% if @level == 2 %>
<%= link_to “edit”, :action => “edit”, :id => message.send(‘id’)
%>
<% elsif @level == 3 %>
<%= link_to “edit”, :action => “edit”, :id => message.send(‘id’)
%>
<%= link_to “destroy”, :action => “destroy”, :id =>
message.send(‘id’) %>
<% end %>

%>
The key to the solution is that link_to does not print out the link,
it only returns the HTML needed for a link. <%= prints out whatever is
passed to it. The if expression returns the last thing it evaluates,
which is then printed by the code which handles the <%=.

So, why does link_to “edit” not get printed out? Becaause it’s return
value is never used, as you go on to evaluate the link_to “destroy”,
the result of which is passed to <%= and printed.

hth,
Douglas