Module: ActiveScaffold::Helpers::ActionLinkHelpers
- Included in:
- ViewHelpers
- Defined in:
- lib/active_scaffold/helpers/action_link_helpers.rb
Overview
Helpers rendering action links
Constant Summary collapse
- NESTED_PARAMS =
params which mustn’t be copying to nested links
i[eid association parent_scaffold].freeze
Instance Method Summary collapse
-
#action_link_authorized?(link, *args) ⇒ Boolean
rubocop:disable Naming/PredicateMethod.
- #action_link_html(link, url, html_options, record) ⇒ Object
- #action_link_html_options(link, record, options, cache: false) ⇒ Object
- #action_link_selected?(link, record) ⇒ Boolean
- #action_link_text(link, record, options) ⇒ Object
-
#action_link_to_inline_form(link, record) ⇒ Object
setup the action link to inline form.
- #action_link_url(link, record) ⇒ Object
- #action_link_url_options(link, record) ⇒ Object
- #add_query_string_to_cached_url(link, url) ⇒ Object
- #cache_action_link?(link) ⇒ Boolean
- #cache_action_link_url?(link, record) ⇒ Boolean
- #cache_action_link_url_options?(link, record) ⇒ Boolean
- #cached_action_link_url(link, record) ⇒ Object
- #cached_action_link_url_options(link, record) ⇒ Object
- #column_in_params_conditions?(key) ⇒ Boolean
- #column_link_authorized?(link, column, record, associated) ⇒ Boolean
- #configure_column_link(link, record, associated, actions = nil) ⇒ Object
- #display_action_link(link, content, record, options) ⇒ Object
- #display_action_link_group(link, record, options) ⇒ Object
- #display_action_link_separator(options) ⇒ Object
- #display_action_links(action_links, record, options, &block) ⇒ Object
- #display_click_menu_link(link, record, options) ⇒ Object
- #display_dynamic_action_group(action_link, links, record_or_ul_options = nil, ul_options = nil) ⇒ Object
- #get_action_link_id(link, record = nil) ⇒ Object
- #ignore_param_for_nested?(key) ⇒ Boolean
- #optional_cache_helper(method, key, cache) ⇒ Object
- #query_string_for_action_links(link) ⇒ Object
- #render_action_link(link, record = nil, options = {}) ⇒ Object
- #render_authorized_action_link(link, record = nil, options = {}, cache: false) ⇒ Object
- #render_unauthorized_action_link(link, record = nil, options = {}, cache: false) ⇒ Object
- #replace_id_params_in_action_link_url(link, record, url) ⇒ Object
-
#replace_tags_for_action_link(html, method, link, label, record, options) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- #replaced_action_link_url_options(link, record) ⇒ Object
- #skip_action_link?(link) ⇒ Boolean
- #sti_record?(record) ⇒ Boolean
- #url_options_for_nested_link(column, record, link, url_options) ⇒ Object
- #url_options_for_sti_link(column, record, link, url_options) ⇒ Object
Instance Method Details
#action_link_authorized?(link, *args) ⇒ Boolean
rubocop:disable Naming/PredicateMethod
14 15 16 17 18 19 20 21 22 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 14 def (link, *args) # rubocop:disable Naming/PredicateMethod auth, reason = if link.security_method_set? || controller.respond_to?(link.security_method, true) controller.send(link.security_method, *args) else args.empty? || args.first.(crud_type: link.crud_type, action: link.action, reason: true) end [auth, reason] end |
#action_link_html(link, url, html_options, record) ⇒ Object
491 492 493 494 495 496 497 498 499 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 491 def action_link_html(link, url, , record) label = .delete(:link) label ||= link.label(record) if url.nil? content_tag(:a, label, ) else link_to(label, url, ) end end |
#action_link_html_options(link, record, options, cache: false) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 424 def (link, record, , cache: false) link_id = cache ? '--LINK_ID--' : [:link_id] || get_action_link_id(link, record) = [:html_options] || link. = .merge(class: [[:class], link.action.to_s].compact.join(' ')) [:link] = action_link_text(link, record, ) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails [:method] = link.method if link.method != :get [:data] ||= {} [:data] = [:data].deep_dup if [:data].frozen? [:data][:confirm] = cache ? '--CONFIRM--' : link.confirm(h(record&.to_label)) if link.confirm? if ![:page] && ![:popup] && ([:inline] || link.inline?) [:class] += ' as_action' [:data][:position] = link.position if link.position [:data][:action] = link.action [:data][:cancel_refresh] = true if link.refresh_on_close [:data][:keep_open] = true if link.keep_open? if link.prompt? [:data][:prompt] = cache ? '--PROMPT--' : link.prompt(h(record&.to_label)) [:data][:prompt_required] = true if link.prompt_required? end [:remote] = true end if link.toggle [:class] += ' toggle' if cache [:class] << ' --ACTIVE--' elsif action_link_selected?(link, record) [:class] << ' active' end end if ![:page] && ![:inline] && ([:popup] || link.popup?) [:target] = '_blank' [:rel] = [[:rel], 'noopener noreferrer'].compact.join(' ') end [:id] = link_id end |
#action_link_selected?(link, record) ⇒ Boolean
410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 410 def action_link_selected?(link, record) if link.respond_to?(:filter_name) if params[link.filter_name] params[link.filter_name].to_s == link.name.to_s else active_scaffold_config.list.filters[link.filter_name].default_option == link.name end else , = (link, record) safe_params = params.to_unsafe_h ( - safe_params.to_a).blank? && .all? { |k, _| params[k].nil? } end end |
#action_link_text(link, record, options) ⇒ Object
384 385 386 387 388 389 390 391 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 384 def action_link_text(link, record, ) if link.image title = [:link] || link.label(record) asset = ActiveScaffold::Registry.cache(:link_images, link.image[:name]) { image_path(link.image[:name]) } text = image_tag(asset, size: link.image[:size], alt: title, title: title, skip_pipeline: true) end text || [:link] end |
#action_link_to_inline_form(link, record) ⇒ Object
setup the action link to inline form
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 183 def action_link_to_inline_form(link, record) link = link.dup associated = record.send(link.column.association.name) if link.column.association&.polymorphic? || link.controller.nil? link.controller = controller_path_for_activerecord(associated.class) return link if link.controller.nil? end link = configure_column_link(link, record, associated) if link.action.nil? link end |
#action_link_url(link, record) ⇒ Object
297 298 299 300 301 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 297 def action_link_url(link, record) url = replace_id_params_in_action_link_url(link, record, cached_action_link_url(link, record)) url = add_query_string_to_cached_url(link, url) if @action_links_urls[link.name_to_cache.to_s] url end |
#action_link_url_options(link, record) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 362 def (link, record) = {action: link.action} [:id] = '--ID--' unless record.nil? [:controller] = link.controller.to_s if link.controller .merge! link.parameters if link.parameters if link.dynamic_parameters.is_a?(Proc) if record.nil? .merge! instance_exec(&link.dynamic_parameters) else .merge! instance_exec(record, &link.dynamic_parameters) end end if link.nested_link? (link.column, record, link, ) elsif nested? [nested.param_name] = '--CHILD_ID--' end (link.column, record, link, ) unless record.nil? || active_scaffold_config.sti_children.nil? [:_method] = link.method if !link.confirm? && link.inline? && link.method != :get end |
#add_query_string_to_cached_url(link, url) ⇒ Object
286 287 288 289 290 291 292 293 294 295 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 286 def add_query_string_to_cached_url(link, url) query_string, non_nested_query_string = query_string_for_action_links(link) nested_params = !link.nested_link? && non_nested_query_string if query_string || nested_params url << (url.include?('?') ? '&' : '?') url << query_string if query_string url << non_nested_query_string if nested_params end url end |
#cache_action_link?(link) ⇒ Boolean
253 254 255 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 253 def cache_action_link?(link) active_scaffold_config.user.cache_action_links && link.type == :member end |
#cache_action_link_url?(link, record) ⇒ Boolean
249 250 251 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 249 def cache_action_link_url?(link, record) active_scaffold_config.user.cache_action_link_urls && link.type == :member && !link.dynamic_parameters.is_a?(Proc) && !sti_record?(record) end |
#cache_action_link_url_options?(link, record) ⇒ Boolean
354 355 356 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 354 def (link, record) active_scaffold_config.user.cache_action_link_urls && (link.type == :collection || !link.dynamic_parameters.is_a?(Proc)) && !sti_record?(record) end |
#cached_action_link_url(link, record) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 257 def cached_action_link_url(link, record) @action_links_urls ||= {} @action_links_urls[link.name_to_cache.to_s] || begin = (link, record) if cache_action_link_url?(link, record) @action_links_urls[link.name_to_cache.to_s] = url_for() else .merge! eid: nil, embedded: nil if link.nested_link? url_for(params_for()) end end end |
#cached_action_link_url_options(link, record) ⇒ Object
358 359 360 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 358 def (link, record) optional_cache_helper(:action_link_url_options, link.name_to_cache.to_s, (link, record), link, record) end |
#column_in_params_conditions?(key) ⇒ Boolean
303 304 305 306 307 308 309 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 303 def column_in_params_conditions?(key) if key.match?(/!$/) conditions_from_params[1..].any? { |node| node.left.name.to_s == key[0..-2] } else conditions_from_params[0].include?(key) end end |
#column_link_authorized?(link, column, record, associated) ⇒ Boolean
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 223 def (link, column, record, associated) if column.association = if column.association.collection? || associated.nil? column.association.klass else associated end , reason = .(crud_type: link.crud_type, reason: true) if link.crud_type == :create && , reason = record.(crud_type: :update, column: column.name, reason: true) end [, reason] else (link, record) end end |
#configure_column_link(link, record, associated, actions = nil) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 194 def configure_column_link(link, record, associated, actions = nil) actions ||= link.controller_actions || [] if column_empty?(associated) # if association is empty, we only can link to create form if actions.include?(:new) link.action = 'new' link.crud_type = :create link.label ||= :create_new end elsif actions.include?(:edit) link.action = 'edit' link.crud_type = :update elsif actions.include?(:show) link.action = 'show' link.crud_type = :read elsif actions.include?(:list) link.action = 'index' link.crud_type = :read end unless (link, link.column, record, associated)[0] link.action = nil # if action is edit and is not authorized, fallback to show if it's enabled if link.crud_type == :update && actions.include?(:show) link = configure_column_link(link, record, associated, [:show]) end end link end |
#display_action_link(link, content, record, options) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 100 def display_action_link(link, content, record, ) if content html_classes = hover_via_click? ? 'hover_click ' : '' if [:level].zero? html_classes += 'action_group' group_tag = :div else html_classes += 'top' if [:first_action] group_tag = :li end content = content_tag(group_tag, class: html_classes.presence, onclick: ('' if hover_via_click?)) do content_tag(:div, link.label(record), class: link.css_class, title: [:title]) << content_tag(:ul, content) end else content = render_action_link(link, record, ) content = content_tag(:li, content, class: ('top' if [:first_action])) unless [:level].zero? end content = content_tag([:level_0_tag], content, [:options_level_0_tag]) if [:level].zero? && [:level_0_tag] content end |
#display_action_link_group(link, record, options) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 68 def display_action_link_group(link, record, , &) if link. (link, record, ) else [:level] += 1 content = display_action_links(link, record, , &) [:level] -= 1 display_action_link(link, content, record, ).tap { [:first_action] = false } if content.present? end end |
#display_action_link_separator(options) ⇒ Object
79 80 81 82 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 79 def display_action_link_separator() tag = [:level_0_tag] || :a if [:level].zero? content_tag(tag || :li, ' '.html_safe, class: 'separator') end |
#display_action_links(action_links, record, options, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 35 def display_action_links(action_links, record, , &block) [:level_0_tag] ||= nil [:options_level_0_tag] ||= nil [:level] ||= 0 [:first_action] = true output = .delete(:output) || ActiveSupport::SafeBuffer.new prev_link = separator = nil action_links.each(reverse: .delete(:reverse), groups: true) do |link| if link == :separator separator = true if prev_link next end content = nil if link.is_a? ActiveScaffold::DataStructures::ActionLinks content = display_action_link_group(link, record, , &block) unless link.empty? elsif !skip_action_link?(link, *Array([:for])) , reason = (link, *Array([:for])) next if ! && [:skip_unauthorized] content = display_action_link(link, nil, record, .merge(authorized: , not_authorized_reason: reason)) [:first_action] = false end next if content.blank? prev_link = true output << display_action_link_separator() if separator output << content separator = false end output end |
#display_click_menu_link(link, record, options) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 84 def (link, record, ) action_link = if link.path.start_with?('collection.') ActiveScaffold::DataStructures::ActionLinks::COLLECTION_CLICK_MENU_LINK else ActiveScaffold::DataStructures::ActionLinks::MEMBER_CLICK_MENU_LINK end html = display_action_link( action_link, nil, record, .merge(authorized: true, link: link.label(record), link_id: get_action_link_id(link, record)) ) html.gsub('--ACTION-LINKS--', ERB::Util.unwrapped_html_escape(link.path)).html_safe # rubocop:disable Rails/OutputSafety end |
#display_dynamic_action_group(action_link, links, record_or_ul_options = nil, ul_options = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 24 def display_dynamic_action_group(action_link, links, = nil, = nil) = if .nil? && .is_a?(Hash) record = unless .is_a?(Hash) ||= {} [:class] = [[:class], 'dynamic-menu'].compact.join(' ') html = content_tag :ul, do safe_join(links.map { |link| content_tag :li, link }) end raw "ActiveScaffold.display_dynamic_action_group('#{get_action_link_id action_link, record}', '#{escape_javascript html}');" # rubocop:disable Rails/OutputSafety end |
#get_action_link_id(link, record = nil) ⇒ Object
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 466 def get_action_link_id(link, record = nil) column = link.column unless link.is_a?(ActiveScaffold::DataStructures::ActionLinks) if column&.association && record associated = record.send(column.association.name) unless column.association.collection? id = if associated "#{column.association.name}-#{associated.id}-#{record.id}" else "#{column.association.name}-#{record.id}" end end id ||= record&.id&.to_s || (nested? ? nested_parent_id.to_s : '') action_link_id = ActiveScaffold::Registry.cache :action_link_id, link.name_to_cache.to_s do if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) action_link_id(link.path.tr('.', '_'), '--ID--') else if params[:parent_controller] || (link.controller && link.controller != controller.controller_path) controller_id = id_from_controller("#{link.controller}-") end action_link_id("#{controller_id}#{link.action}", '--ID--') end end action_link_id.sub('--ID--', id) end |
#ignore_param_for_nested?(key) ⇒ Boolean
311 312 313 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 311 def ignore_param_for_nested?(key) NESTED_PARAMS.include?(key) || column_in_params_conditions?(key) || (nested? && nested.param_name == key) end |
#optional_cache_helper(method, key, cache) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 140 def optional_cache_helper(method, key, cache, ...) if cache ActiveScaffold::Registry.cache(method, key) { send(method, ...) } else send(method, ...) end end |
#query_string_for_action_links(link) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 315 def query_string_for_action_links(link) if defined?(@query_string) && link.parameters.none? { |k, _| @query_string_params.include? k } return [@query_string, @non_nested_query_string] end keep = true @query_string_params ||= Set.new = {} = {} params_for.except(:controller, :action, :id).each do |key, value| @query_string_params << key if link.parameters.include? key keep = false next end if ignore_param_for_nested?(key) [key] = value else [key] = value end end if nested_singular_association? && action_name == 'index' # pass current path as return_to, for nested listing on singular association, so forms doesn't return to parent listing @query_string_params << :return_to [:return_to] = request.fullpath end query_string = .to_query if .present? if .present? non_nested_query_string = "#{'&' if query_string}#{non_nested_query_string_options.to_query}" end if keep @query_string = query_string @non_nested_query_string = non_nested_query_string end [query_string, non_nested_query_string] end |
#render_action_link(link, record = nil, options = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 121 def render_action_link(link, record = nil, = {}) if link.action.nil? || link.column&.association&.polymorphic? link = action_link_to_inline_form(link, record) if link.column&.association [:authorized] = false if link.action.nil? || link.controller.nil? .delete :link if link.crud_type == :create end method = if link.action.nil? || (link.type == :member && .key?(:authorized) && ![:authorized]) :render_unauthorized_action_link else :render_authorized_action_link end cache_link = cache_action_link?(link) label = [:link] result = optional_cache_helper(method, link.name_to_cache.to_s, cache_link, link, record, , cache: cache_link) cache_link ? (result, method, link, label, record, ) : result end |
#render_authorized_action_link(link, record = nil, options = {}, cache: false) ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 174 def (link, record = nil, = {}, cache: false) url = cache ? '--URL--' : action_link_url(link, record) [:link] = '--LABEL--' if cache = (link, record, , cache: cache) html = action_link_html(link, url, , record) cache ? html.to_str : html end |
#render_unauthorized_action_link(link, record = nil, options = {}, cache: false) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 162 def (link, record = nil, = {}, cache: false) html_class = "disabled #{link.action}#{" #{link.html_options[:class]}" if link.html_options[:class].present?}" [:link] = '--LABEL--' if cache = { link: action_link_text(link, record, ), class: html_class, title: cache ? '--REASON--' : [:not_authorized_reason] } html = action_link_html(link, nil, , record) cache ? html.to_str : html end |
#replace_id_params_in_action_link_url(link, record, url) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 270 def replace_id_params_in_action_link_url(link, record, url) url = record ? url.sub('--ID--', record.to_param.to_s) : url.dup if link.column&.association&.singular? child_id = record.send(link.column.association.name)&.to_param if child_id.present? url.sub!('--CHILD_ID--', child_id) else url.sub!(/\w+=--CHILD_ID--&?/, '') url.sub!(/\?$/, '') end elsif nested? url.sub!('--CHILD_ID--', params[nested.param_name].to_s) end url end |
#replace_tags_for_action_link(html, method, link, label, record, options) ⇒ Object
rubocop:disable Metrics/ParameterLists
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 148 def (html, method, link, label, record, ) # rubocop:disable Metrics/ParameterLists case method when :render_unauthorized_action_link html = html.gsub('--REASON--', ERB::Util.unwrapped_html_escape([:not_authorized_reason])) when :render_authorized_action_link html = html.gsub('--URL--', ERB::Util.unwrapped_html_escape(action_link_url(link, record))) .gsub('--LINK_ID--', ERB::Util.unwrapped_html_escape([:link_id] || get_action_link_id(link, record))) .gsub('--CONFIRM--') { ERB::Util.unwrapped_html_escape(link.confirm(h(record&.to_label))) } .gsub('--PROMPT--') { ERB::Util.unwrapped_html_escape(link.prompt(h(record&.to_label))) } .gsub('--ACTIVE--') { action_link_selected?(link, record) ? 'active' : '' } end html&.gsub('--LABEL--', h(label || link.label(record)))&.html_safe # rubocop:disable Rails/OutputSafety end |
#replaced_action_link_url_options(link, record) ⇒ Object
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 393 def (link, record) url = (link, record) url[:controller] ||= params[:controller] , = url.partition { |_, v| v.nil? } replacements = {} replacements['--ID--'] = record.id.to_s if record if link.column&.association&.singular? replacements['--CHILD_ID--'] = record.send(link.column.association.name)&.id.to_s elsif nested? replacements['--CHILD_ID--'] = params[nested.param_name].to_s end .collect! do |k, v| [k.to_s, replacements[v] || v] end [, ] end |
#skip_action_link?(link) ⇒ Boolean
10 11 12 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 10 def skip_action_link?(link, *) !link.ignore_method.nil? && controller.respond_to?(link.ignore_method, true) && controller.send(link.ignore_method, *) end |
#sti_record?(record) ⇒ Boolean
241 242 243 244 245 246 247 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 241 def sti_record?(record) return false unless active_scaffold_config.active_record? model = active_scaffold_config.model record && model.columns_hash.include?(model.inheritance_column) && record[model.inheritance_column].present? && !record.instance_of?(model) end |
#url_options_for_nested_link(column, record, link, url_options) ⇒ Object
501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 501 def (column, record, link, ) if column&.association [:parent_scaffold] = controller_path [column.model.name.foreign_key.to_sym] = .delete(:id) [:id] = ('--CHILD_ID--' if column.association.singular? && [:action].to_sym != :index) elsif link.parameters&.dig(:named_scope) [:parent_scaffold] = controller_path [active_scaffold_config.model.name.foreign_key.to_sym] = .delete(:id) [:id] = nil end end |
#url_options_for_sti_link(column, record, link, url_options) ⇒ Object
513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/active_scaffold/helpers/action_link_helpers.rb', line 513 def (column, record, link, ) # need to find out controller of current record type and set parameters # it's quite difficult to detect an sti link # if link.column.nil? we are sure that it isn't a singular association inline autolink # however that will not work if a sti parent is a singular association inline autolink return unless link.column.nil? return if (sti_controller_path = controller_path_for_activerecord(record.class)).nil? [:controller] = sti_controller_path [:parent_sti] = controller_path end |