首页 > 解决方案 > 在 Rails 5.2 中使用 materializeCss 卡片创建复选框

问题描述

我正在使用 Ransack 构建一个带有一些过滤器的 Rails 应用程序,我不希望用户能够使用如下图所示的卡片搜索属性。当他们在我的数据库中选择一张将返回的卡时。 在此处输入图像描述

我目前的搜查表格

    <%= search_form_for @q, html: {autocomplete: 'off'}  do |f| %>
        <div class="container">
            <div class="row">

               <!--APARTMENT CARD-->
                <div class="col l6 s6">
                    <div class="card-panel hoverable b-radius5px">
                        <img style="width:60px;" class="center" src="https://res.cloudinary.com/craftwebs/image/upload/v1584137944/condominium_pltgkr.svg" alt="">
                        <span class="center blue-grey-text text-lighten-2" style="margin-left: -15px;">Apartment</span>
                    </div>
                </div>

                <!--HOUSE CARD-->
                <div class="col l6 s6">
                    <div class="card-panel hoverable z-depth-1 b-radius5px">
                        <img style="width:60px;" class="center" src="https://res.cloudinary.com/craftwebs/image/upload/v1584138119/real-estate_mugxx7.svg" alt="">
                        <span class="center blue-grey-text text-lighten-2">House</span>
                    </div>
                </div>


                <div class="center">
                    <%= f.submit "Search", class:" waves-effect blue-kafasa-bn waves-light btn b-radius15px" %>
                </div>

现在,我能够搜索这些属性的唯一方法是通过选择:

<div class="col l6 m6 s12">
<%= f.select(:propertytype_eq, options_for_select(['Apartment', 'Office', 'House' ]), {:include_blank => 'Pick a property'} ) %>
 </div>

在此处输入图像描述

这是当我使用select在我的应用程序中搜索特定属性时它在我的日志中的外观:

  Parameters: {"utf8"=>"✓", "q"=>{"price_gteq"=>"", "price_lteq"=>"", "propertytype_eq"=>"Apartment"}, "commit"=>"Search"}

如何让用户使用卡片而不是选择来搜索属性?我需要修改物化复选框吗?

标签: ruby-on-railsruby-on-rails-5materializeransack

解决方案


您是否尝试对卡片使用 onclick 功能?您可以添加一个 onclick 事件来启动导航或为您想要的选项设置标志/变量。


推荐阅读