我想弄清楚如何根据条件禁用复选框?
这是我从视图中看到的一段代码:
<%= f.collection_check_boxes(:company_ids, @user_companies, :id, :name) do |b| %>
<div class="col-sm-1">
<%= b.check_box %>
</div>
<%= b.label %><br><br>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我需要将其禁用,如果@user = current_user
在collection_check_boxes 文档中,我不知道如何实现此目的。我认为有某种方法,但到目前为止还没有找到一种方法。我天真的想法是也许条件可以以某种方式表述出来。这里的答案展示了如何使用 check_box_tag 来做到这一点。
我很高兴收到任何解决此问题的提示。谢谢你!
我试图实现包括在has_many/ belongs_to类似于此示例关联:
class Author < ApplicationRecord
has_many :books, -> { includes :line_items }
end
class Book < ApplicationRecord
belongs_to :author
has_many :line_items
end
class LineItem < ApplicationRecord
belongs_to :book
end
Run Code Online (Sandbox Code Playgroud)
在那一刻,我做@author.books我看到我的控制台IT负载Book和LineItem和显示的记录Book,没有记录LineItem.我尝试时得到未定义的方法错误@author.books.line_items.也没有@author.line_items工作.
请问如何获取LineItem记录Author?谢谢!
我<%= simple_form_for @offer, remote: true %>启用了 Turbolinks。我正在尝试在我的update操作中使用以下内容重定向并显示成功闪烁:
respond_to do |format|
if @offer.update(offer_params)
flash[:success] = "#{@offer.name} #{t(:updated)}"
format.html { redirect_to seller_offers_path }
format.js
else
format.html { render :edit }
end
end
Run Code Online (Sandbox Code Playgroud)
我的update.js.erb代码与重定向或闪存无关:
$(".ibox-content.actions").removeClass('sk-loading');
$('.sk-spinner').css("display", "none");
Run Code Online (Sandbox Code Playgroud)
在 application.html.erb 中,我可以用这个渲染 flash:
<div class="row">
<% flash.each do |message_type, message| %>
<%= content_tag(:div, content_tag(:strong, message), id: "flash_message",
class: "text-bold alert alert-#{message_type}") %>
<% end %>
</div>
Run Code Online (Sandbox Code Playgroud)
目前我的表单已保存,但没有重定向。
当我添加Turbolinks.visit(<%= seller_offers_path %>)的update.js.erb形式保存,重定向做,但没有闪光灯。
有没有办法让我可以在带有 Turbolinks 的重定向页面上显示 Flash remote: …