Ruby on rails 3.2 搜索和命名的路由。。。模板缺失

Ruby on rails 3.2 搜索和命名的路由。。。模板缺失,ruby-on-rails-3.2,ransack,Ruby On Rails 3.2,Ransack,当我搜索任何内容时,总是会出现以下错误: 缺少后台模板/用户/搜索、应用程序/搜索 {:locale=>[:en],:formats=>[:html],:handlers=>[:erb,:builder, :咖啡]}。搜索位置:“*”C:/RailsApps/Novaxons/app/views” 我在应用程序/模型中有一个用户模型 class User < ActiveRecord::Base attr_accessible :email, :password, :password_

当我搜索任何内容时,总是会出现以下错误:

缺少后台模板/用户/搜索、应用程序/搜索 {:locale=>[:en],:formats=>[:html],:handlers=>[:erb,:builder, :咖啡]}。搜索位置:“*”C:/RailsApps/Novaxons/app/views”

我在应用程序/模型中有一个用户模型

class User < ActiveRecord::Base
  attr_accessible :email, :password, :password_confirmation, :remember_me, :created_by, :active, :blocked, :profile_attributes
  has_secure_password


  # relations
  has_one :profile, :dependent => :destroy, :inverse_of => :user
  accepts_nested_attributes_for :profile

 [...]
如您所见,我使用名称空间路由来拥有一个管理面板(称为backstage)

index.html.erb

<div id="table-users-grid">
  <div id="grid-top-pagination" class="row">

    <div class="span4"><%= will_paginate %></div>
    <div class="span4 page-entries-info"><%= page_entries_info %></div>
    <div id="search-area" class="span4">
      <%= search_form_for @q, :url => search_backstage_users_path, :html => {:method => :post} do |sf| %>
          <div class="search-form-fields">
            <%= sf.text_field :email_cont, :placeholder => 'search users email contains' %>
          </div>
          <div class="actions"><%= sf.submit "Search" %></div>
      <% end %>
    </div>
  </div>
  <div id="management-area" class="row">
    <table id="users-grid" class="span10">
      <thead>
      <tr>
        <th><%= link_to 'UID', :sort => "id" %></th>
        <th><%= link_to 'Last name', :sort => "profiles.last_name" %></th>
        <th><%= link_to 'First name', :sort => "profiles.first_name" %></th>
        <th><%= link_to 'Email', :sort => "email" %></th>
        <th><%= link_to 'Country', :sort => "profiles.country" %></th>
        <th>active</th>
        <th>blocked</th>
        <th>created_at</th>
        <th>created_by</th>
      </tr>
      </thead>
      <tbody>
      <% @users.each do |user| %>
          <tr>
            <td><%= user.id %></td>
            <td><%= user.profile.last_name %></td>
            <td><%= user.profile.first_name %></td>
            <td><%= user.email %></td>
            <td><%= user.profile.country %></td>
            <td><%= user.active %></td>
            <td><%= user.blocked %></td>
            <td><%= user.created_at.strftime("%d %B %Y") %></td>
            <td><%= user.created_by %></td>
            <td><%= link_to 'Show', backstage_user_profile_path(user, user.profile) %></td>
            <td><%= link_to 'Edit', edit_backstage_user_profile_path(user, user.profile) %></td>
            <td><%= link_to 'Destroy', backstage_user_path(user), confirm: 'Are you sure?', method: :delete %></td>
          </tr>
      <% end %>
      </tbody>
      <tfoot></tfoot>
    </table>
    <aside id="switch-view-wrapper" class="btn-group btn-group-vertical span2" data-toggle="buttons-radio">
      <%= link_to 'All', backstage_users_path, :class => 'btn' %>
      <%= link_to 'Active', backstage_active_users_path, :class => 'btn' %>
      <%= link_to 'Inactive', backstage_active_users_path, :class => 'btn' %>
      <%= link_to 'Blocked', backstage_active_users_path, :class => 'btn' %>
      <%= link_to 'Not Blocked', backstage_active_users_path, :class => 'btn' %>
    </aside>
  </div>

  <div id="grid-bottom-pagination">
    <%= will_paginate %>
  </div>
</div>

现在一切都好了

我还必须将其添加到作用域中,对于那些对控制器中的作用域活动的感兴趣的人来说,代码将变为

def active
    @q = User.search(params[:q])
    @users = @q.result(:distinct => true).active.paginate(:per_page => 5, :page => params[:page])
    render 'index'
  end 
用户模型中定义如下

# scopes
  scope :active, joins(:profile).where(:active => true)
希望这能对其他人有所帮助


干杯

添加答案并接受它;不要把答案放在问题里。我对你的
搜索方法也不感兴趣。如果您有通用的init逻辑,那么用一个单独的方法将其隔离;调用index然后呈现它是令人困惑的,而使用一个实际上不是index方法的index方法也是令人困惑的。看起来你的答案(错误地嵌入到一个问题中)部分解决了这个问题,但是很抱歉,如果你对我刚才遵循的gem文档和RailsCast的搜索方法不感兴趣的话。
 # Search
      def search
        index
        render :index
      end
    end
# Search
  def search
    @q = User.search(params[:q])
    @users = @q.result(:distinct => true).paginate(:per_page => 5, :page => params[:page])
    render 'index'
  end
def active
    @q = User.search(params[:q])
    @users = @q.result(:distinct => true).active.paginate(:per_page => 5, :page => params[:page])
    render 'index'
  end 
# scopes
  scope :active, joins(:profile).where(:active => true)