user1175969
user1175969

Reputation: 570

View must get dynamically build path from a helper

I currently have the following link in a View:

<li><%= link_to "Classrooms", '/institutes/1/courses' %></li>

I want to get path "'/institutes/1/courses'" from a helper method. Please let me know how I do that, and I can call the helper in my View.

Upvotes: 0

Views: 52

Answers (1)

Ronan Lopes
Ronan Lopes

Reputation: 3398

You can add it to your class helper and call it directly there. For example, if your model call "posts", you can have a file posts_helper.rb inside your helpers folder with something like

module PostsHelper
  def your_method
  end
end

and in your view,

<li><%= link_to "Classrooms", your_method %></li>

You can also add it to application_helper.rb, but you should do that only if you intend to use it globally.

Upvotes: 1

Related Questions