Closed heka1024 closed 1 year ago
@heka1024 Hi, thank you for the Pull Request!
params
is not available in class level, so making it available only within nested
seems weird to me.
helper introduced recently could be a solution for this problem, but I haven't tried it so maybe I'm wrong.
Let me look into some possibilities for other solutions.
@heka1024 I noticed that the code below works:
class FooResource
include Alba::Resource
nested :foo do
def service
SomeService.new(params[:user])
end
attribute :bar do |foo|
service.bar
end
attribute :baz do |foo|
service.baz
end
end
end
This is not intuitive but is a solution for your problem. I'm closing this issue in favor of this solution, but feel free to reopen it if there's some problem.
Motivation
In our usecase, we want to write code like below.
However, we can't do that because
params
is not available in the block.Modification
params
in the block ofnested
method.