Reputation: 310
def admin_options_for_registrar(registrar)
if registrar.enrollment_application != nil && registrar.enrollment_application.status == "Complete"
["Show", "/registrars/"+registrar.id.to_s],["Edit", "/edit_registrars/"+registrar.id.to_s], ["Dashboard", "/homes/"+registrar.enrollment_application.id.to_s], ]
else
["Show", "/registrars/"+registrar.id.to_s],["Edit", "/edit_registrars/"+registrar.id.to_s], ["Dashboard", "/homes/"+registrar.enrollment_application.id.to_s], ]
end
end
This helper method I wrote in model file Now I am calling this method in view file this way
<% if xyx!= nil? %>
<td><%= select_tag "options", options_for_select([admin_option_for_registrar])
<% end %>
and this should give me the drop down with Edit, Show and Dashboard but it gives me error undefined mentod ' admin_options_for_registrar'
Any help??
Upvotes: 0
Views: 50
Reputation: 239541
Helper methods should go in a helper file in 'app/helpers', not in the model file.
As written, it sounds like you've created an instance method for your model, which you're trying to invoke without an instance.
Update
There are numerous other problems with the function itself:
]
's on both branches of your ifreturn
keywordregistrar
) but you're not passing one in[]
Try to get the following working, and then add the branching logic back in:
def admin_options_for_registrar(registrar)
[
["Show", "/registrars/"+registrar.id.to_s],
["Edit", "/edit_registrars/"+registrar.id.to_s],
["Dashboard", "/homes/"+registrar.enrollment_application.id.to_s]
]
end
# pass the registrar object into your function
<%= select_tag "options", options_for_select(admin_option_for_registrar(registrar))
Upvotes: 1