なぜ私のコードが機能しないのか理解できません
私は次を持っています:
people/index.html.erb
=>
<% @people.each do |i| %>
<tr>
<td><%= i.id %></td>
<td><%= i.name %></td>
<td><%= link_to i.country_id, root_path(:country_id => i.country_id) %></td>
<td><%= i.state_id %></td>
</tr>
<% end %>
people_controller:
def index
@people = Person.all
@people = @people.by_country_id(params[:country_id]) if params[:country_id].present?
end
person.rbで
scope :by_country_id, lambda { |x| where(:country_id => x) }
root :to => 'people#index'
link_to をクリックすると、country_id を持つすべての人が受信されます
出力には ...localhost:3000/?country_id=1001 があります
NoMethodError in PeopleController#index
undefined method `by_country_id'
どこを間違えますか?