Rails Block Helper similar to form_for with resource routine
Im struggling trying to make a helper class that works with blocks like
the form_for do |f|. I think I have it working but I cant seem to be able
to use routing. It seems the way I have it setup routing is unavailable in
the class, but I cant find any way to correct it.
I want to be able to do this
<%= nav_list do |nl| %>
<%= nl.link @model.name, @model %>
<% end %>
My helper file is setup like this:
module NavListHelper
class NavList
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
def header(title)
content_tag :li, title, class: 'nav-header'
end
def link(title, path)
link_to title, path
end
end
def nav_list(&block)
new_block = Proc.new do
helper = NavList.new
block.call(helper)
end
content_tag :ul, capture(&new_block), class: 'nav nav-list'
end
end
The issue is being able to use link_to (and url_for) when I pass a model
object to it.
No comments:
Post a Comment