开发者

Rails - view: Ruby code in link_tag

I'd like to have embededd ruby code as my link name. Right now I tried to implement it like this:

<% @user.each do |user| %>
    <li><%= link_to '<%= user.familyname %>, <%= user.forename %> ', user %> </li>
<% end %>

But it's not working, Rails gives me a syntax error:

syntax error, unexpected $undefined, expecting ')'
...);@output_buffer.safe_concat('\', user %> </li>
...                               ^

What do I need to change in the syntax, 开发者_StackOverflow社区so this Link will work?


you can not do <%= %> inside an <%= %>. you can try something like this:

    <% @users.each do |employee| %>
        <li><%= link_to "#{employee.familyname}, #{employee.forename}", employee %> </li>
    <% end %>


Just simple

<%= link_to [user.familyname, user.forename].join(','), user_path %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜