在我的Ruby on Rails應用程序我有方法,看起來像這樣:問題和Rails的link_to如果方法
def survey_pack_signed_off(sp, type)
signed_off = Util::Boolean.humanize(sp.survey_pack_sign_off.present?)#returns Yes if true and No if false
return signed_off if type == :csv
if sp.survey_pack_sign_off.present?
link_to signed_off, admin_survey_pack_sign_off_path(sp.survey_pack_sign_off)
else
signed_off
end
end
我試圖重構它和使用Rails的link_to_if方法:
def survey_pack_signed_off(sp, type)
signed_off = Util::Boolean.humanize(sp.survey_pack_sign_off.present?)#returns Yes if true and No if false
return signed_off if type == :csv
link_to_if (type == :html && sp.survey_pack_sign_off.present?), signed_off, admin_survey_pack_sign_off_path(sp.survey_pack_sign_off)
end
但此link_to_if導致以下錯誤:
ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"admin/survey_pack_sign_offs", :format=>nil, :id=>nil} missing required keys: [:id]
爲什麼此代碼無效?
你能向我們展示行動'survey_pack_sign_offs'的路線? – RPinel 2015-04-02 16:00:59