在我的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