以下のerb
に記載のコードをhelper
に移動したく、2つ目のコードの通りにメソッドを書きましたが
undefined method count for nil:NilClass
といったエラーが出てしまいます。
誤りをご指摘頂くたくお願いします
ruby
1### 以下erbファイルに記載してます 2 3<% @answered_makeup_questions_ids = user.answered_makeup_questions.map(&:root_id).uniq %> 4<% if user.posted_makeup_questions.present? %> 5<% @my_posted_makeup_questions_ids = user.posted_makeup_questions.map(&:id) %> 6<% @answered_makeup_questions_ids.delete_if { |id| @my_posted_makeup_questions_ids.include?(id) } %> 7<% end %> 8 9<%= @answered_makeup_questions_ids.count %></strong></div> 10
ruby
1### adviser_helper.rb 2 3module AdviserHelper 4 require "uri" 5 6 def my_answered_question_ids(user) 7 answered_makeup_questions_ids = user.answered_makeup_questions.map(&:root_id).uniq 8 if user.posted_makeup_questions.present? 9 my_posted_makeup_questions_ids = user.posted_makeup_questions.map(&:id) 10 answered_makeup_questions_ids.delete_if { |id| my_posted_makeup_questions_ids.include?(id) } 11 end 12 end 13 14end 15 16 17### view(erbファイル) 18<%= my_answered_question_ids(user).count %>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/21 03:46