Collection blocks - custom controller action
gauravtiwari opened this issue · 6 comments
Hello Daniel,
I have a custom controller action and relevant view file in curly (followers). Also, I have a layout presenter which basically acts as parent presenter for all view blocks that are common to that controller.
I am trying to implement collection block as per your documentation but it's throwing an error -
required identifier
user missing
class Users::FollowersPresenter < ProfileLayoutPresenter
def followers
@user.followers(User)
end
def followings
@user.followees(User)
end
end
And then I have relevant follower and following (singular) presenter for presenting fields. Please let me know what I am doing wrong ?
Please note, I also added presents :user in the code but the error is same. Since, it's inheriting from the parent it should have user variable.
Thank you,
Gaurav
@dasch Can confirm that it's only happening on custom controller methods.
required identifier
user missing
Also, how does a presenter extract an instance variable from controller? For ex - if I have a custom followers method and have an instance variable (@followers) with assigned data. How do I access that variable in followerspresenter?
Hi @gauravtiwari, sorry for the late response. Can you paste a minimal reproducible example to a gist?
One quick question: since you inherit presents :user
from the parent presenter class, you must set @user
in the controller action if you render the template directly as a view, or pass it to render
if you render it as a partial.
@dasch I did the same thing in my controller action but can't seem to use it in my presenter class. The parent presenter has: ruby presents: user
and since, I am inheriting from parent presenter the variable should be present. Also, I am passing ruby locals: {user: @user}
in my partial, like so
Can you create a gist with a complete example?
I was able to reproduce the bug – it was caused by an error in the way the parameters were forwarded. The fix will be released in v2.1.