[英]how to add an bootstrap icon to simple_form's link_to_remove_association and link_to_add_association
Like the question says, I would like to put an icon into the link_to_add_association
and link_to_remove_association
s.就像问题所说的那样,我想在link_to_add_association
和link_to_remove_association
放置一个图标。
I'm using Ruby Rails, and simple_form
, and I would like to put a bootstrap icon, rather than the words 'Add line', and 'Remove'.我正在使用 Ruby Rails 和simple_form
,我想放置一个引导程序图标,而不是“添加行”和“删除”这两个词。
This is what the code looks like.这就是代码的样子。 The f
, in the code below is from a loop these are in.下面的代码中的f
来自它们所在的循环。
<%= link_to_add_association 'Add line', f, :weeks %>
and和
<%= link_to_remove_association 'Remove', f, :weeks %>
Thank you in advance!提前谢谢你!
I'm not sure whether you received an answer to your question yet but have you tried checking your attr_accessible in Dashacts.我不确定您是否收到了问题的答案,但您是否尝试过在 Dashacts 中检查您的 attr_accessible。 I think you need to add options_attributes.我认为您需要添加 options_attributes。
Tell me how that works out for you.告诉我这对你有什么作用。
link_to_add_association
is an user defined helper method. link_to_add_association
是用户定义的辅助方法。 In that method, we have link_to
tag.在那个方法中,我们有link_to
标签。 Go to your link_to_add_association
method(It may be in your helper), there should be a link_to
tag.转到您的link_to_add_association
方法(它可能在您的助手中),应该有一个link_to
标签。 For example, In my link_to_add_association
例如,在我的link_to_add_association
def link_to_add_association(f, association, **args)
###your code goes here
link_to('#', class: "xyx " , data: {id: xyz}) do
"<span class='fa fa-male fa-lg'>".html_safe
end
end
I have used the font-awesome icon.我使用了字体真棒图标。 You can use bootstrap icon instead.您可以改用引导程序图标。
You can try this answer.你可以试试这个答案。 I am using rails 5.2.我正在使用导轨 5.2。 Ruby version 2.4.1红宝石版本 2.4.1
The correct Version is .正确的版本是.
.links
= link_to_add_association f, :user_permissions, partial: 'permissions/shared/user_permission_fields', class: 'btn btn-primary' do
%i.fa.fa-fw.fa-database
The mistake is you put 'Add new'错误是你把“添加新的”
.links
= link_to_add_association 'Add New', f, :user_permissions, partial: 'permissions/shared/user_permission_fields', class: 'btn btn-primary' do
%i.fa.fa-fw.fa-database
Bootstrap or font awesome icon can be added by using a block like this:可以使用这样的块添加 Bootstrap 或字体真棒图标:
<%= link_to_remove_association f, :weeks do %>
<i class="fa fa-minus-circle"></i>
<% end %>
This will replace "Remove" with the minus icon.这将用减号图标替换“删除”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.