ruby-on-rails - 在 Rails 中搜索时索引页面不会重新呈现/刷新
问题描述
我正在索引页面上的 rails 中进行简单搜索。我的问题是在调试时我得到了正确的结果,但它们没有显示在前端。
def index
if !params[:category].present? and !params[:title].present?
@services = Service.take(4)
else
if params[:category] != "Find Service" and params[:title].present?
@services = Service.where(category: params[:category], title: params[:title]).take(4)
elsif params[:category] == "Find Service" and params[:title].present?
@services = Service.where(title: params[:title]).take(4)
elsif params[:category] != "Find Service" and !params[:title].present?
@services = Service.where(category: params[:category]).take(4)
else
@services = Service.take(4)
end
end
end
我的观点 index.html.erb
<%= form_with(url: "services", method: "get") do |form| %>
<div class="banner-input" style="margin-top">
<div class="listing-sort listing-sort--main-listing" style="width: 50%;float: left; border-radius: 6px; border: 2px solid white; background: transparent; padding: 0px;">
<input type="submit" value="" class="main-listing__form-field agent-submit" style="width: 10% ;float:right">
<%= form.text_field "title", id: "search_agent", class: "main-listing__form-field ", placeholder: "Search by Name or Location...", style: "width: 75% ;float:right; background: transparent; color: white!;" %>
<div class="listing-sort__inner" style="float:left;margin: 0px; width: 25%; padding: 0px;">
<p class="listing-sort__sort">
<%= form.select("category",options_for_select(["Find Service", "Assembly", "Carpet Cleaning", "Electrical", "House Cleaning", "HVAC", "Handyman", "IT", "Junk Removal", "Lawn Care","Moving", "Painting", "Plumbing", "Staging", "Photography", "Videography", "Inspectors"], :selected => "Find Service"), {include_blank: false}, { :class => 'ht-field listing-sort__field' }) %>
</p><!-- .listing-sort__sort -->
</div><!-- .listing-sort__inner -->
</div><!-- .listing-sort -->
</div>
<% end %>
<section style="margin-top: 50px">
<h2 style="margin-left: 15px; padding-bottom: 30px; font-size: 24px;">Recently viewed & more</h2>
<% @services.each do |service| %>
<%= render 'services/service_card', :f => service %>
<% end %>
</section>
<section class="jumbotron"style="margin-top: 50px">
<h2 style="margin-left: 15px; padding-bottom: 30px; font-size: 24px;">Pro SEM services
</h2>
<% @services.each do |service| %>
<%= render 'services/service_card', :f => service %>
<% end %>
</section>
这是_service_card
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-3" style="padding-bottom: 10px">
<div class="boxes">
<div class="box-img">
<img src="assets/MobileApps.png">
</div>
<div class="user-detail-main">
<div class="user-detail-img">
<img src="assets/MobileApps.png">
</div>
<div class="user-detail">
<a><h3><%= f.user.profile.first.first_name %></h3></a>
<p>Level 1 Seller</p>
</div>
<div class="user-detail-para">
<% byebug %>
<p><%= f.description %></p>
</div>
<div style="padding-top: 50px;">
<i class="fas fa-star" style="color: #ffbf00"></i> (5)
</div>
</div>
<div class="user-detail-footer">
<div class="heart-icon">
<i class="fas fa-heart" style="color: #c6c6c6"></i>
<i class="fas fa-bars" style="color: #c6c6c6"></i>
</div>
<div class="user-value">
<p>Starting At $ <%= f.packages.first.price%></p>
</div>
</div>
</div>
请帮助我解决这个问题。期待。没有搜索它工作正常,但搜索它不会更新结果并显示相同的结果。
解决方案
推荐阅读
- php - php 替换字符串 Preg_match
- angular - 如何在打字稿中重新排序表的序列号
- spring - 如何在 Spring Boot 中使用 Spring-DM
- android - Recycler 视图中的 Recycler 视图
- bash - 如何从文件内容中提取数据,包括字符串并忽略换行
- javascript - 如何使用 Promise 等待函数执行以等待其在 Javascript/Node JS 中的回调
- php - 如何在 laravel 构建器上执行“解释选择”
- codenameone - 禁用 PeerComponent 的滚动 (GoogleMap)
- c# - Cefsharp 如何显示新添加的 PrintPreview
- java - 什么偏移量用于从 Postgres 时间戳TZ 中解组 OffsetDateTime?