Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix namespacing issues for links in render helpers #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app/helpers/render_expandable_tree_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# or use h.html_escape(node.content)
# for escape potentially dangerous content
module RenderExpandableTreeHelper
module Render
module Render
class << self
attr_accessor :h, :options

Expand All @@ -30,8 +30,7 @@ def render_node(h, options)

def show_link
node = options[:node]
ns = options[:namespace]
url = h.url_for(ns + [node])
url = h.url_for(:controller => kontroller, :action => :show, :id => node)
title_field = options[:title]

"<h4>#{ h.link_to(node.send(title_field), url) }</h4>"
Expand All @@ -40,13 +39,13 @@ def show_link
def controls
node = options[:node]

edit_path = h.url_for(:controller => options[:klass].pluralize, :action => :edit, :id => node)
show_path = h.url_for(:controller => options[:klass].pluralize, :action => :show, :id => node)
edit_path = h.url_for(:controller => kontroller, :action => :edit, :id => node)
destroy_path = h.url_for(:controller => kontroller, :action => :destroy, :id => node)

"
<div class='controls'>
#{ h.link_to '', edit_path, :class => :edit }
#{ h.link_to '', show_path, :class => :delete, :method => :delete, :data => { :confirm => 'Are you sure?' } }
#{ h.link_to '', destroy_path, :class => :delete, :method => :delete, :data => { :confirm => 'Are you sure?' } }
</div>
"
end
Expand All @@ -57,6 +56,10 @@ def children
end
end

def kontroller
options[:controller] ||= options[:klass].pluralize
end

end
end
end
end
12 changes: 7 additions & 5 deletions app/helpers/render_sortable_tree_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# or use h.html_escape(node.content)
# for escape potentially dangerous content
module RenderSortableTreeHelper
module Render
module Render
class << self
attr_accessor :h, :options

Expand All @@ -29,8 +29,7 @@ def render_node(h, options)

def show_link
node = options[:node]
ns = options[:namespace]
url = h.url_for(:controller => options[:klass].pluralize, :action => :show, :id => node)
url = h.url_for(:controller => kontroller, :action => :show, :id => node)
title_field = options[:title]

"<h4>#{ h.link_to(node.send(title_field), url) }</h4>"
Expand All @@ -39,8 +38,8 @@ def show_link
def controls
node = options[:node]

edit_path = h.url_for(:controller => options[:klass].pluralize, :action => :edit, :id => node)
destroy_path = h.url_for(:controller => options[:klass].pluralize, :action => :destroy, :id => node)
edit_path = h.url_for(:controller => kontroller, :action => :edit, :id => node)
destroy_path = h.url_for(:controller => kontroller, :action => :destroy, :id => node)

"
<div class='controls'>
Expand All @@ -56,6 +55,9 @@ def children
end
end

def kontroller
options[:controller] ||= options[:klass].pluralize
end
end
end
end
9 changes: 6 additions & 3 deletions app/helpers/render_tree_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def render_node(h, options)

def show_link
node = options[:node]
ns = options[:namespace]
url = h.url_for(ns + [node])
url = h.url_for(:controller => kontroller, :action => :show, :id => node)
title_field = options[:title]

"<h4>#{ h.link_to(node.send(title_field), url) }</h4>"
Expand All @@ -40,6 +39,10 @@ def children
end
end

def kontroller
options[:controller] ||= options[:klass].pluralize
end

end
end
end
end