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

Remove the use of resource controller instance variables for passing things down to the view #220

Open
jensljungblad opened this issue Feb 21, 2017 · 0 comments

Comments

@jensljungblad
Copy link
Collaborator

jensljungblad commented Feb 21, 2017

While using instance variables for this is a Rails thing, we're not big fans of this. We're thinking about using locals instead, if possible.

Currently we have all these methods that only sets an instance variable:

before_action :set_resource_service
before_action :set_resource_class
before_action :set_resource_parents
before_action :set_resources, only: :index
before_action :set_resource, only: [:show, :new, :edit, :create, :update, :destroy]

Look into if it's possible to do something like:

def index
  locals = index_locals
  
  respond_to do |format|
    format.html { locals: locals }
    format.json { locals: locals }
    format.csv { locals: locals }
  end
end

protected

def index_locals
  { 
    resource_service: resource_service,
    resource_class: resource_class,
    resources: resources 
  }
end

Discussion regarding using locals: thoughtbot/guides#398, https://thepugautomatic.com/2013/05/locals/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Godmin 2.0
Discussions
Development

No branches or pull requests

1 participant