ruby-on-rails – 如何预先检查formtastic中的复选框

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 如何预先检查formtastic中的复选框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个表单我正在设置…
用户可以有很多帖子,每个帖子可以让很多人看到它.

手表模型以多视角设置为“可监视”,因此可应用于不同类型的模型.它具有user_id,watchable_id,watchable_type和timestamp作为属性/字段.

这是soley,所以当人们对帖子发表评论时,观看帖子的用户可以收到关于它的电子邮件.

我想要做的是向用户显示他们可以在每个帖子上标记用户列表,这是没有问题的.这是我现在正在使用的

http://pastie.org/940421

<% semantic_form_for @update do |f| %>
      <%= f.input :subject,:input_html => { :class => 'short' } %>
      <%= f.input :site,:include_blank => false,:input_html => { :class => 'short' } %>
      <label>Tag Users (they will get notified of this update)</label>
       <%= f.input :user,:as => :check_Boxes,:label => '&nbsp;',:wrapper_html => { :class => "radiolist clearfix" },:for => :watch,:name => "Watch" %>

      <%= f.input :note,:label => 'Update'%>
      <% f.buttons do %>
        <%= f.commit_button :button_html => { :class => 'submit' } %>
      <% end %>
    <% end %>

这个问题是,当你去编辑一个更新/发布…所有的复选框被预先检查…我希望它预先检查正在观看这个职位的用户.

要进一步澄清…这是我现在正在做我想要的那种奇怪的方式

<ul class="radiolist clearfix">
<% @users.each do |user| %>
    <li>
    <%= check_Box_tag 'user_ids[]',user.id,@watches.include?(user.id) ? true : false -%>
    <%= h user.name -%>
    </li>
<% end %>
</ul>

其中@watches只是用户ID的数组

@watches = @update.watches.map{|watcher| watcher.user_id}

解决方法

对于任何有同样问题的人:
<%= f.input :some_input,:as => :boolean,:input_html => { :checked => 'checked' } %>
原文链接:https://www.f2er.com/ruby/273830.html

猜你在找的Ruby相关文章