Revision c45a0014
Added by Ohad Levy over 12 years ago
- ID c45a0014cee4b8a530ab25beb9a7b1eb5cd7b037
app/helpers/application_helper.rb | ||
---|---|---|
# Display a link if user is authorized, otherwise a string
|
||
# +name+ : String to be displayed
|
||
# +options+ : Hash containing
|
||
# :enable_link : Boolean indicating whether the link is to be displayed
|
||
# :controller : String or Symbol representing the controller
|
||
# :auth_action : String or Symbol representing the action to be used for authorization checks
|
||
# +html_options+ : Hash containing html options for the link or span
|
||
def link_to_if_authorized(name, options = {}, html_options = {})
|
||
enable_link = options.has_key?(:enable_link) ? options.delete(:enable_link) : true
|
||
enable_link = html_options.has_key?(:disabled) ? !html_options[:disabled] : true
|
||
auth_action = options.delete :auth_action
|
||
if enable_link
|
||
link_to_if authorized_for(options[:controller] || params[:controller], auth_action || options[:action]), name, options, html_options
|
||
else
|
||
content_tag(:span, name, {:class => "entry"}.merge(html_options))
|
||
link_to_function name, 'void()', html_options
|
||
end
|
||
end
|
||
|
||
... | ... | |
# :controller : String or Symbol representing the controller
|
||
# :auth_action : String or Symbol representing the action to be used for authorization checks
|
||
# +html_options+ : Hash containing html options for the link or span
|
||
def display_link_if_authorized(name, options = {}, html_options = nil)
|
||
def display_link_if_authorized(name, options = {}, html_options = {})
|
||
auth_action = options.delete :auth_action
|
||
if authorized_for(options[:controller] || params[:controller], auth_action || options[:action])
|
||
enable_link = html_options.has_key?(:disabled) ? !html_options[:disabled] : true
|
||
if enable_link and authorized_for(options[:controller] || params[:controller], auth_action || options[:action])
|
||
link_to(name, options, html_options)
|
||
else
|
||
""
|
Also available in: Unified diff
fixes #1167 - some setting values are ignored