Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access current_account in models in Padrino?
    primarykey
    data
    text
    <p>I'm working on a Padrino application that has a main App and an Admin app. When a user logins through session, I just run the following two lines to log him in.</p> <pre><code>account = Account.authenticate(params[:email], params[:password]) set_current_account(account) </code></pre> <p>With debugger in any controllers in Admin</p> <pre><code>current_account #&lt;Account @id=1 @name="John" @surname="Davies" @email="john.davies@gmail.com" @crypted_password="3456789" @role="admin"&gt; </code></pre> <p>With debugger in any models</p> <pre><code>current_account *** NameError Exception: undefined local variable or method `current_account' for #&lt;Post @id=1 @question="Why is this not working?" @answer="I have no idea"&gt; </code></pre> <p>I am able to access current_account to find out which user is logged in in the Admin app, but this variable is not accessible in the main App. </p> <p>What I am trying to do is that I am creating an Activity Feed, or Audit Trail, for all my models, so when a record is created/updated/destroyed in any model, a new record is created in model Activity. That being said, I need to access the current_account variable in my models.</p> <p>I have searched for solutions, and came across a suggestion:</p> <p>In admin/app.rb</p> <pre><code>enable :sessions set :session_id, "my-global-session" </code></pre> <p>In app/app.rb</p> <pre><code>register Padrino::Admin::AccessControl register Padrino::Admin::Helpers enable :sessions set :session_id, "my-global-session" </code></pre> <p>It did not work for me. Is there a way I can access current_account in my models? </p> <p>Thank you for any guide or suggestion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload