1
我有一個奇怪的錯誤與ransack。它返回錯誤未定義的方法`boarding_eq'的Ransack ::搜索<class:School,base:Grouping <combinator:and >>:Ransack ::搜索
undefined method `boarding_eq' for Ransack::Search<class: School, base: Grouping <combinator: and>>:Ransack::Search
for;
<div class="form-group col-xs-6 pull-left">
<%= f.label :boarding_eq, " Boarding Facilities", class: 'search-label ' %>
<%= f.select :boarding_eq, options_for_select(["","Yes", "No"]), class: 'form-control col-xs-12' %>
</div>
然而,它適用於所有其他輸入,如;
<div class="form-group col-xs-6 pull-left">
<%= f.label :year_of_establishment_eq, " Boarding Facilities", class: 'search-label ' %>
<%= f.select :year_of_establishment_eq, options_for_select(["","Yes", "No"]), class: 'form-control col-xs-12' %>
</div>
學校模型看起來像這樣;
class School < ActiveRecord::Base
attr_accessible :about, :academic_level, :country, :boarding, :district_or_province,
:email_address, :fees, :gender, :information_technology, :number_of_students,
:performing_arts, :phone_number, :photo_1, :photo_2, :photo_3, :photo_4,
:photo_5, :physical_address, :post_address, :school_name, :sports, :town,
:web_address, :year_of_establishment
validates :about, :academic_level, :country, :boarding, :district_or_province,
:email_address, :gender, :information_technology, :number_of_students,
:performing_arts, :phone_number, :physical_address, :post_address, :school_name,
:sports, :town, presence: true
validates :email, :with => /\A[A-Za-z0-9._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]+\z/, uniqueness:true
validates :phone_number, uniqueness:true, numericality: true, length: {minimum: 12}
belongs_to :user
has_many :school_events
has_many :school_reviews
has_many :votes
has_one :rating
end
和模型遷移如下;
class CreateSchools < ActiveRecord::Migration
def change
create_table :schools do |t|
t.integer :user_id
t.string :school_name
t.integer :year_of_establishment
t.string :number_of_students
t.string :academic_level
t.string :phone_number
t.string :email_address
t.string :web_address
t.text :physical_address
t.integer :post_address
t.string :country
t.string :district_or_province
t.string :town
t.text :about
t.string :fees
t.string :sports
t.string :information_technology
t.string :performing_arts
t.string :gender
t.string :boarding
t.text :photo_1
t.text :photo_2
t.text :photo_3
t.text :photo_4
t.text :photo_5
t.timestamps
end
add_index :schools, [:user_id, :year_of_establishment]
add_index :schools, [:school_name, :number_of_students]
add_index :schools, [:academic_level, :country ]
add_index :schools, [ :district_or_province, :fees ]
add_index :schools, [:boarding, :gender ]
end
end
我已經添加了學校模型和學校遷移。
請顯示你的學校模型的細節。此外,什麼類型的屬性是'登機'? –
@GraemeMcLean,我已經添加了他們 – Acacia
想不到爲什麼它不喜歡這個領域,但對所有其他人都沒問題。在構建搜索或獲取結果時出現錯誤嗎?在堆棧跟蹤中還有其他用處嗎? –