开发者

Regarding helper method?

开发者 https://www.devze.com 2023-02-14 09:53 出处:网络
def admin_options_for_registrar(registrar) if registrar.enrollment_application != nil && registrar.enrollment_application.status == \"Complete\"
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 th开发者_开发技巧is should give me the drop down with Edit, Show and Dashboard but it gives me error undefined mentod ' admin_options_for_registrar'

Any help??


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:

  • seems you have a syntax error in your function, there are extra ]'s on both branches of your if
  • both branches of your if are identical; why have an if at all?
  • your function isn't returning anything; you need the return keyword
  • your function takes an argument (registrar) but you're not passing one in
  • your enclosing the result of the function in an addtional array by calling it withing []

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))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号