and can’t understand why my code is not work
i have next:
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
in person.rb
scope :by_country_id, lambda { |x| where(:country_id => x) }
root :to => ‘people#index’
i want, when i click in link_to, i received all people with country_id
in the output i have …localhost:3000/?country_id=1001
NoMethodError in PeopleController#index
undefined method `by_country_id'
where i mistake ?
Change
To