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

Ruby 2.7.5, Rails 6.1.4.4, Administrate 0.16.0 undefined batch_action_name #12

Open
stepheneb opened this issue Jan 20, 2022 · 1 comment

Comments

@stepheneb
Copy link

The controller method SitesController#export_batch_action is undefined when rendering app/views/admin/application/index.html.erb

Context: Ruby 2.7.5, Rails 6.1.4.4, Administrate 0.16.0

Comparing all changes between main and administrate_batch_actions branches:
https://github.com/stepheneb/wts-rails6/compare/main...administrate_batch_actions

ActionView::Template::Error (undefined local variable or method `export_batch_action' for #<ActionView::Base:0x0000000000b2c0>
Did you mean?  export_batch_action_admin_sites_url):
    34: 
    35:   <%=
    36:     administrate_batch_actions_button(
    37:       export_batch_action,
    38:       export_batch_action_admin_sites_path,
    39:       { class: '', confirm: '' }
    40:     )
  
app/views/admin/application/index.html.erb:37

In the interactive console under the view error and asking for tab completion on in-scope objects starting with export.

>> export 
export_batch_action_admin_sites_path export_batch_action_admin_sites_url

My controller with a method named: export_batch_action

module Admin
  class SitesController < Admin::ApplicationController
    def export_batch_action
      Site.find(params[:batch_action_ids]).each(&:export)
      redirect_to :admin_sites, notice: "Successfully exported #{params[:batch_action_ids].size} sites"
    end
  end
end

And model with a Site#export method

class Site < ApplicationRecord
  def export
  end
end
@andreibondarev
Copy link
Member

@stepheneb Ah! In your example here:

ActionView::Template::Error (undefined local variable or method `export_batch_action' for #<ActionView::Base:0x0000000000b2c0>
Did you mean?  export_batch_action_admin_sites_url):
    34: 
    35:   <%=
    36:     administrate_batch_actions_button(
    37:       export_batch_action,
    38:       export_batch_action_admin_sites_path,
    39:       { class: '', confirm: '' }
    40:     )
  
app/views/admin/application/index.html.erb:37

export_batch_action should be replaced with just a string that gets passed on to the link_to tag. In your case this should fix it:

    35:   <%=
    36:     administrate_batch_actions_button(
    37:       'Batch Export',
    38:       export_batch_action_admin_sites_path,
    39:       { class: '', confirm: '' }
    40:     )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants