-
Notifications
You must be signed in to change notification settings - Fork 15
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
Pass in variable into presenter #45
Comments
Hey @vinnyglennon. We expose module Api
module V1
module Helper
def current_user
ActiveRecord::Base.current_user
# works in our user model, but you may need to put it on Thread.current.
end
end
end
end
Brainstem::Presenter.helper(Api::V1::Helper) |
I'm very open to discussion better methods. |
Hi, Instead, my idea is that a url has an auth_token. In the controller I find the correct user, and somehow pass it to the presenter. Exposing it to presenter is my issue. The helper will never have access to it, as its only in the controller. Currently, is there any way to pass an object to presenter directly? |
That's a good point. I'll take a look at letting you pass objects through to presenters, unless you'd like to take a crack at it. |
Hmmm, just noticed using Thread.current is causing rspec to fail, as rspec keeps referring to an older Thread.current. It does not look like a viable solution for this :( |
I will work on getting some sort of solution for this into the next version of Brainstem. |
Url: /api/v1/videos?auth_token=11112323432432
In controllors/api/v1/videos
I can easily get the user from the auth_token. I want to then make it available in the presenter, ideally via render :json => present("videos") { videos, :extra => user }
Is it possible to pass variables to presenter?
render :json => present("videos") { Widget.visible_to(current_user) } does not work in this case, as in the presenter, I want to show different information, depending on the user
I am currently storing the user_id in a thread in a controller:
Thread.current[:user_id] = 1
and accessing that in the presenter, but this is far less than ideal.
The text was updated successfully, but these errors were encountered: