实施RefineryCMS搜索引擎

时间:2013-05-02 16:28:54

标签: ruby-on-rails refinerycms

我正在尝试实施RefineryCMS搜索引擎,我已按照指南https://github.com/refinery/refinerycms-search#search-plugin-for-refinery-cms上的步骤操作,但是当我在自定义扩展程序上实现此操作时,我可能会遗漏一些内容:

application.rb中:

config.to_prepare do
  Refinery.searchable_models = [Refinery::Doctors::Doctor]
end

型号:

module Refinery
  module Doctors
    class Doctor < Refinery::Core::BaseModel
      self.table_name = 'refinery_doctors'

      attr_accessible :prefix, :full_name, :bio, :specialty, :branch, :schedule, :location, :position, :dr_img, :dr_img_id

      acts_as_indexed :fields => [:prefix, :full_name, :bio, :specialty, :branch, :schedule, :location, :dr_img, :dr_img_id]
      alias_attribute :title, :full_name

      validates :prefix, :presence => true
      belongs_to :dr_img, :class_name => '::Refinery::Image'
      has_many :branches
    end
  end
end

控制器:

  def show

    # you can use meta fields from your model instead (e.g. browser_title)
    # by swapping @page for @doctor in the line below:
    present(@page)
  end

protected

  def find_all_doctors
    @doctors = Doctor.order('branch ASC').paginate(:page => params[:page], :per_page => 20)

  end

查看:

<div class="clearfix">
<div class="span3 dotted">
<% content_for :side_body do %>
  <aside>
    <h2>Otros Especialistas<%#= t('.other') %></h2>

      <% @doctors.each do |doctor| %>
        <% if @doctor.branch == doctor.branch && @doctor.full_name != doctor.full_name %>
          <ul id="doctors">
            <li>
              <%= link_to doctor.prefix + ' ' + doctor.full_name, refinery.doctors_doctor_path(doctor) %>
            </li>
          </ul>  

      <% end %>
    <% end %>
  </aside>
<% end %>

</div>   


<div class="clearfix">
<% content_for :body do %>
  <section>
        <div class="span3">
                <p><%= image_fu @doctor.dr_img, '250x250'%></p>
        </div>

        <div class="span4">
      <h1><%= @doctor.prefix + ' ' + @doctor.full_name %></h1>
      <h2><%= @doctor.specialty %></h2>
        <strong>Horario: </strong><%=raw @doctor.schedule %><br>
        <strong>Consultorio: </strong><%=raw @doctor.location %>
        <h3>Biografía:</h3>
        <p>
          <%=raw @doctor.bio %>
        </p>


        </div>

  </section>
<% end %>


<%= render '/refinery/content_page' %>
</div>

错误:

https://gist.github.com/jmercedes/5503185

1 个答案:

答案 0 :(得分:1)

@doctor未在代码中的任何位置定义。您需要将以下行添加到控制器中的#show操作。

  

@doctor = Doctor.find(params[:id])