ruby on rails - Dynamic Paths in Helper -


I am trying to create an assist method for my admin link in some views I have code

  & lt;% if current_user% & gt; & Lt;% = link_to "edit", edit_model_path (model)%> & Lt;% = link_to "new", new_model_path%> & gt; & Lt;% = link_to "Delete", model ,: confirmation => "You are a Noble" ,: Method = & gt; :% & Gt; Remove & lt;% end% & gt;  

Displays only when it's logged in.

I would like to do something like this at their place

  <% = admin_link (model)%>  

and pass the current item into auxiliary instrument

  def admin_links (m) if current_user a = "# {link_to" edit "edit_m_path ( M)} "a & lt; & Lt; "# {Link_to" new "new_m_path}" a & lt; & Lt; "## {link_to" delete ", m,: confirmation =>" Your Noble ",: Method = & gt ;: Delete}" Expiration  

or something like that

Basically you have to change something to indicate the name of the class of the model in the correct path.

model_name = m.class.to_s.underscore

and then use it to call the appropriate path methods

  link_to "edit", "send_" {edit_name} _path ", m)  

on one side, you link_tos to # {} because This function only returns a string.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -