开发者

Use link_to helper wrap some HTML

开发者 https://www.devze.com 2023-03-09 00:20 出处:网络
I want to use link_to wrap some HTML,but I meet some problem. <%= link_to \'index\', { :controller => \"user\" , :action => \"resume\" }, :class => is_active?(\"index\") do %>

I want to use link_to wrap some HTML,but I meet some problem.

<%= link_to 'index', { :controller => "user" , :action => "resume" }, :class => is_active?("index") do %>
  <li class="usidebar-index">index</li>
<% end %> 

<a href="index" controller="user" action="resume">
  <li class="usidebar-index">index</li>
</a>

I also have tried:

<%= link_to 'index',{ 开发者_开发问答:controller => "user", :action => "resume" },  :class => is_active?("index") do %>
  <li class="usidebar-index">index</li>
<% end %>

<a href="index" action="resume" controller="user">
  <li class="usidebar-index">indx</li>
</a>

What I want is:

<a href="index" class="some-style">
  <li class="usidebar-index">index</li>
</a>

Could you help me?Thank you.


per the rails documentation:

<%= link_to({:controller => "user" , :action => "resume" }, :class => is_active?("index")) do %>

  <li class="usidebar-index">index</li>

<% end %>


If you're supplying a block to link_to, the (normal) first argument of the link text is no longer required.

So I'm guessing you want this instead:

<%= link_to {:controller => 'user', :action => 'resume'}, :class => is_active?('index') do %>
  <li class="usidebar-index">index</li>
<% end %>


Try:

<%= link_to content_tag(:li, :class => "usidebar-index"),{ :controller => "user", :action => "resume" },  :class => is_active?("index") do %>

Although, it's quite odd to see an li within an a tag. Usually it's the other way around.

0

精彩评论

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