Note that there are some explanatory texts on larger screens.

plurals
  1. POcurrent_user not stored in session on production server
    primarykey
    data
    text
    <p>I'm having a difference between dev and production (on a shared webserver). In my application controller I have these 2 lines as part of a method which stores updates:</p> <pre><code>@activity.update_attribute(:user_id, current_user.id) @activity.update_attribute(:company_id, current_user.company.id) </code></pre> <p>In dev both the user_id and company_id are known and get saved in the database. This is because there is a before filter which stores the session info in the current_user.</p> <p>But with the exact same code on the shared production server, it gives an error when it stores the record to the database and when I look in the log these both values are NULL. The error is: </p> <pre><code>"ActiveRecord::StatementInvalid (Mysql2::Error: Column 'company_id' cannot be null: INSERT INTO `activities` (`activity`, `company_id`, `created_at`, `updated_at`, `user_id`) VALUES ('Test', NULL, '2011-12-09 09:01:29', '2011-12-09 09:01:29', NULL)):" </code></pre> <p>To me it seems on production the session isn't stored properly. I've searching around and the only think I can find is this article, which says you have to add "allow_http_basic_auth" to the user model. When I do that (I'm not using Authlogic by the way), then it returns this error:</p> <pre><code>undefined method `allow_http_basic_auth' for #&lt;User:0x007f91990efce0&gt; </code></pre> <p>Any ideas would be great!</p> <p>Edit: in the application controller I have this:</p> <pre><code> helper_method :current_user def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end # Save new activity/update def store_update(activity) @activity = Activity.new @activity.update_attribute(:activity, activity) @activity.update_attribute(:user_id, current_user.id) @activity.update_attribute(:company_id, current_user.company.id) @activity.save end </code></pre>
    singulars
    1. This table or related slice is empty.
    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