什么是使用由Twitter的引导提供在Rails 3中的链接图标的最佳方式?
目前,我使用它就像粘贴的片段,但是当我用我的平板电脑看网页图标不显示。 我敢肯定有使用Twitter的引导图标为on Rails的3链路提供了更好的方式。
<%= link_to(vote_against_mission_mission_path(:id => mission.id), :method => :post) do %>
<i class="icon-chevron-down blank-vote enlarge"></i>
<% end %><br />
<%= link_to(collect_mission_path(controller: "folders", action: "collect", id: mission.id)) do %>
<i class="icon-heart blank-favorite enlarge" id="actions-centering"></i>
如果你建立这样一个帮手:
module BootstrapIconHelper
def icon_link_to(path, opts = {}, link_opts = {})
classes = []
[:icon, :blank].each do |klass|
if k = opts.delete(klass)
classes << "#{klass}-#{k}"
end
end
classes << "enlarge" if opts.delete(:enlarge)
opts[:class] ||= ""
opts[:class] << " " << classes.join(" ")
link_to content_tag(:i, "", opts), path, link_opts
end
end
你可以写你的链接是这样的:
<%= icon_link_to(
vote_against_mission_mission_path(:id => mission.id),
{ :icon => "chevron-down", :blank => "vote", :enlarge => true },
{:method => :post}
) %>
<%= icon_link_to(
collect_mission_path(controller: "folders", action: "collect", id: mission.id),
{ :icon => "heart", :blank => "favorite", :enlarge => true, id: "action-centering}
) %>
除非我误解你以后,rigamarole方式少:
<%= link_to('', vote_against_mission_mission_path(:id => mission.id), :class => "chevron-down") %>
我要创建这个帮手:
module BootstrapHelper
def icon(*names)
content_tag(:i, nil, :class => icon_classes(names))
end
private
def icon_classes(*names)
names.map{ |name| "icon-#{name}" }
end
end
而使用这样的:
link_to icon(:trash, :white), user_path(@user), method: :delete
上述解决方案在返回这样的:
<i class="icon-[:remove, :white]"></i>
我改变出头,而现在为我工作:
module BootstrapHelper
def icon(*names)
content_tag(:i, nil, :class => icon_classes(names))
end
private
def icon_classes(*names)
final = ""
names[0].each do |n|
final = final + "icon-" + n.to_s + " "
end
return final
end
end
现在它返回它:
<i class="icon-remove icon-white "></i>
使用是一样的:
<%= link_to icon(:remove, :white), doc, :confirm => 'Are you sure?', :method => :delete %>
使用的link_to与图标引导
<%= link_to edit_idea_path(idea), class: 'btn btn-default' do %>
<span class="glyphicon glyphicon-pencil"></span>
Edit
<% end %>
<%= link_to new_idea_path, class: 'btn btn-primary btn-lg' do %>
<span class="glyphicon glyphicon-plus"></span>
New Idea
<% end %>
<%= link_to idea, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' do %>
<span class="glyphicon glyphicon-remove"></span>
Destroy
<% end %>
http://railsgirls.co.il/en/guides/design/list-page/icons.html