# Problem with elsif

**URL:** <https://www.ruby-forum.com/t/problem-with-elsif/100089>\
**Category:** Rails\
**Created:** [July 27, 2006, 2:21am UTC](https://www.ruby-forum.com/t/problem-with-elsif/100089 "2006-07-27T02:21:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pipogol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@pipogol](https://www.ruby-forum.com/u/pipogol)\
**Post date:** [July 27, 2006, 2:21am UTC](https://www.ruby-forum.com/t/problem-with-elsif/100089/1 "2006-07-27T02:21:16Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![pipogol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@pipogol](https://www.ruby-forum.com/u/pipogol)\
**Post date:** [July 27, 2006, 3:40am UTC](https://www.ruby-forum.com/t/problem-with-elsif/100089/2 "2006-07-27T03:40:43Z")

</div>

help please, im trying everything and nothing

---

<div class="post-metadata">

**Author:** ![pipogol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@pipogol](https://www.ruby-forum.com/u/pipogol)\
**Post date:** [July 27, 2006, 9:27am UTC](https://www.ruby-forum.com/t/problem-with-elsif/100089/3 "2006-07-27T09:27:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pipogol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@pipogol](https://www.ruby-forum.com/u/pipogol)\
**Post date:** [July 27, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/problem-with-elsif/100089/4 "2006-07-27T18:28:07Z")

</div>

On 7/26/06, pipogol [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 %\>

---

<div class="post-metadata">

**Author:** ![pipogol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@pipogol](https://www.ruby-forum.com/u/pipogol)\
**Post date:** [July 27, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/problem-with-elsif/100089/5 "2006-07-27T18:52:24Z")

</div>

> %\>  
> 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
