【问题标题】:Rails Search Not Working On Mobile with HerokuRails 搜索无法在 Heroku 的移动设备上运行
【发布时间】:2014-05-25 23:50:28
【问题描述】:

我遇到了一个有趣的情况。我目前正在运行一个非常基本的应用程序,并且我有一个搜索用户的搜索功能(设计 gem)。它在本地很好用,在 Heroku 上也很好用。这是一个移动优先的网络应用程序,所以我也一直在使用 Nitrous.io 在移动设备上对其进行测试。我提到这一点是因为搜索功能正在移动设备上运行,目前仅在 iOS Safari 和 Chrome 上使用 Nitrous.io 的云服务器进行了测试。

话虽如此,似乎当我在移动设备上运行该应用程序时,在 Heroku 上,它只是没有显示我的搜索结果。我觉得我只是错过了一些非常愚蠢的东西。

这是我的用户模型:

def self.search(search)
 search.blank? ? [] : all(:conditions => ['email LIKE ?', "%#{search.strip}%"])
end

这是我的看法:

<% if (@user) %>
 <% if (@user.empty?) %>
  <p>Search for your connections by email address!</p>
 <% else %>
  <% @user.each do |user| %>  
   <% if current_user.email == "#{user.email}" %>
     <!-- display nothing -->
   <% end %>
   <div class="search-card">
    <%= link_to image_tag(user.avatar), user %></p>
    <%= link_to "#{user.firstName}", user %>
    <%= link_to "#{user.lastName}", user %>
    <%= link_to "#{user.company}", user %>
    <%= link_to "#{user.email}", user %>
     <% if current_user.friends.exists?(user) %>
      <%= link_to "View this connection", user, :class => "btn btn-add" %>
     <% else %>
      <%= link_to "View this person", user, :class => "btn btn-add" %>
      <%= link_to "Add Friend", friendships_path(:friend_id => user), :class => "btn btn-add", :method => :post %>
     <% end %>
   </div>
  <% end %>
<% end %>
<% end %>
<% end %>

在我看来,这里是搜索表单:

<%= form_tag(users_path, :method => "get", id: "search-form", class: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search Users", class: "search-form" %>

【问题讨论】:

    标签: ios ruby-on-rails jquery-mobile heroku devise


    【解决方案1】:

    我想通了。是的,这真的很简单。

    它只在移动和 Heroku 上同时被破坏的原因是因为我的移动搜索默认第一个字母为大写字母,而我的桌面浏览器搜索仅以小写进行。

    基本上,Postgres 不接受大写搜索。为了解决这个问题,我只是在我的用户模型中添加了一些 ruby​​ 来自动缩小搜索。

    将我的用户模型更改为:

    def self.search(search)
      search.blank? ? [] : all(:conditions => ['email LIKE ?', "%#{search.downcase}%"])
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      • 2017-01-28
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-19
      相关资源
      最近更新 更多