はじめまして。
Ruby on Railsにて実装しているプログラムでエラーが発生し、解決方法がわかりません。
ご教示いただけないでしょうか?
error
1 2NoMethodError (undefined method `index' for nil:NilClass): 3 4app/controllers/customers_controller.rb:40:in `show'
show
1 def show 2 @customer = Customer.find(params[:id]) 3 @call = Call.new 4 @customer_ids = params[:customer_ids] 5 current_index = @customer_ids.index(params[:id].to_s) 6 ↑40行目 7 if current_index > 0 && current_index + 1 < @customer_ids.size 8 prev_index = current_index - 1 9 prev_customer_id = @customer_ids[prev_index] 10 @prev_customer = Customer.find_by(id: prev_customer_id) 11 12 next_index = current_index + 1 13 next_customer_id = @customer_ids[next_index] 14 @next_customer = Customer.find_by(id: next_customer_id) 15 elsif current_index == 0 16 next_index = current_index + 1 17 next_customer_id = @customer_ids[next_index] 18 @next_customer = Customer.find_by(id: next_customer_id) 19 elsif current_index + 1 == @customer_ids.size 20 prev_index = current_index - 1 21 prev_customer_id = @customer_ids[prev_index] 22 @prev_customer = Customer.find_by(id: prev_customer_id) 23 end 24 end
解決のご教示いただけると幸いです。
よろしくお願い致します。
show を呼ぶ view を見れば原因が判るかと