0
을 선택하고 내 코드는 내가 가지고범위와
작동하지 않는 이유를 이해할 수 없다 다음 : 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) }
,210
루트 : 내가 LINK_TO 클릭 => '사람 # 지수'내가 원하는
에, 내가 localhost를 ... 난이 출력에 country_id
모든 사람들을받은 : 3000/country_id = 1001
NoMethodError in PeopleController#index
undefined method `by_country_id'
나는 실수 하나?
에'@people = Person.all''당신에게'Person' 객체의 배열을 제공하고 그래서 당신은 방법을 적용 할 수 없습니다 by_country_id' 배열에 그리고 그렇게하려고하면 배열에 대한 메서드 정의되지 않은 메서드 by_country_id가 발생합니다. – Salil
예 (첫 번째 답변 주석에 있음) –