简体   繁体   English

如何将引导图标添加到 simple_form 的 link_to_remove_association 和 link_to_add_association

[英]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_associationlink_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.您可以改用引导程序图标。

Reference: link_to参考: link_to

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.

相关问题 link_to_add_association 和 link_to_remove_association 嵌套表单 Cocoon gem - link_to_add_association and link_to_remove_association Nested form Cocoon gem 茧link_to_add_association不起作用 - Cocoon link_to_add_association not working link_to_remove_association没有删除? - link_to_remove_association is not removing? 仅在单击link_to_add_association后如何显示关联字段? - How to show association fields only after click on link_to_add_association? 当表单中只有一行/项目时,如何使用 rails 中的 link_to_remove_association 隐藏删除链接 - how to hide remove link when there is only one row/item in the form using link_to_remove_association in rails Rails茧动态创建link_to_add_association - Rails cocoon dynamic creation of link_to_add_association 空的link_to_add_association用于茧形嵌套属性 - Empty link_to_add_association for cocoon nested attributes link_to_add_association添加两个部分而不是一个 - link_to_add_association adding two partials instead of one Rails 带有 Cocoon 的嵌套字段 - link_to_add_association 正在删除记录 - Rails Nested Fields With Cocoon - link_to_add_association is Deleting Records 有没有办法重新生成 link_to_add_association (特别是数据关联插入模板)? - Is there a way to regenerate link_to_add_association (specifically data-association-insertion-template)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM