You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't have a great answer for this, but I've patched Trestle::Resource::Builder and modified some things at runtime before:
class Trestle::Resource::Builder
def location_from_current_location
params_with_location_from_current_attributes
finder_scoped_location
collection_scoped_location
end
def params_with_location_from_current_attributes
self.class.include Hack
end
def collection_scoped_location
admin.include CollectionHack
end
def finder_scoped_location
admin.include FinderHack
end
module CollectionHack
def prepare_collection(params, options={})
if model.columns_hash['location_id']
super.where(location_id: Current.location.id)
else
super
end
end
end
module FinderHack
def find_instance(params)
if model.columns_hash['location_id']
model.find_by(id: params[:id], location_id: Current.location.id)
else
model.find(params[:id])
end
end
end
module Hack
def params(&block)
if admin.model.columns_hash['location_id']
super.tap do |p|
p[:location_id] = Current.location.id
end
else
super
end
end
end
end
And then in my admin resources:
Trestle.resource(:movies) do
location_from_current_location
end
It's ugly and feels awful but it got me what I needed.
Guys, i'm with a problem. My question is how use concerns with trestle? Exist someaway of use?
The text was updated successfully, but these errors were encountered: