У меня возникла проблема, когда записи не возвращаются из базы данных. Ошибок не возникает, но, возможно, я пропустил что-то простое. Я установил для своей базы данных yml для разработки, тестирования и производства одну и ту же вещь, чтобы убедиться, что я нацелился на эту базу данных.Простые рельсы 3 Запрос не загружает данные
Запрос непосредственно из базы данных возвращает 3 учреждения.
Модель - institution.rb
class Institution < ActiveRecord::Base
# attr_accessible :title, :body
has_many :childinstitutions, :class_name => "Institution",
:foreign_key => "parentinstitution_id"
belongs_to :parentinstitution, :class_name => "Institution"
def self.search(term)
if term
Institution.where('institutionname LIKE ?', :term).all
else
Institution.all
end
end
end
контроллер - institutions_controller.rb
class InstitutionsController < ApplicationController
def index
@institutions = Institution.search(params[:term])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @institutions }
end
end
def show
@institution = Institution.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @institution }
end
end
def new
@institution = Institution.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @institution }
end
end
end
View - учреждения/index.html.erb
<h1>Listing Institutions</h1>
<table>
<tr>
<th>Id</th>
<th><% @institutions.length %> records</th>
</tr>
<% for institution in @institutions %>
<tr>
<td><% institution.id %></td>
<td></td>
</tr>
<% end %>
</table>
<br />
Действительно большой Листинг-учреждения и идентификационные записи на следующей строке.