Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this method not work in my controller ? - Rails 3
    primarykey
    data
    text
    <p>This is semi-related to this question: <a href="https://stackoverflow.com/questions/5844813/how-do-i-get-the-storage-of-each-user-account-to-update-when-a-new-file-is-upload">How do I get the storage of each user account to update when a new file is uploaded - in Rails 3?</a></p> <p>But it actually is a bit different, because it involves a specific action in my controller.</p> <p>This is the controller action (<code>upload_controller.rb</code>):</p> <pre><code>def destroy upload = Upload.find(params[:id]) upload.destroy respond_to do |format| format.html { redirect_to("/") } format.js { render :json =&gt; ['upload',params[:id]].to_json, :layout =&gt; false } end current_user.update_space end </code></pre> <p>This is my <code>User.rb</code> model:</p> <pre><code># == Schema Information # Schema version: 20110412170916 # # Table name: users # # id :integer not null, primary key # email :string(255) # encrypted_password :string(128) # password_salt :string(255) # reset_password_token :string(255) # remember_token :string(255) # remember_created_at :datetime # sign_in_count :integer # current_sign_in_at :datetime # last_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_ip :string(255) # username :string(255) # first_name :string(255) # last_name :string(255) # created_at :datetime # updated_at :datetime # invitation_token :string(60) # invitation_sent_at :datetime # plan_id :integer # current_state :string(255) # confirmation_token :string(255) # confirmed_at :datetime # confirmation_sent_at :datetime # space_used :integer default(0), not null # failed_attempts :integer default(0) # unlock_token :string(255) # locked_at :datetime # trial_end_date :date # active_subscription :boolean # class User &lt; ActiveRecord::Base acts_as_voter devise :database_authenticatable, :confirmable, :registerable, :timeoutable, :recoverable, :rememberable, :trackable, :validatable, :invitable, :lockable attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :first_name, :last_name, :plan_id has_friendly_id :username, :use_slug =&gt; true, :strip_non_ascii =&gt; true before_save :update_space has_many :uploads def role_symbols roles.map do |role| role.name.underscore.to_sym end end def update_space total_size = 0 if self.uploads.count &gt; 0 self.uploads.each do |upload| total_size += upload[:image_file_size] end end self.space_used = total_size end def space_left (self.plan.storage * 1024 * 1024 * 1024) - self.space_used.to_f end end </code></pre> <p>The line in question is in the <code>upload_controller.rb</code> where it says <code>current_user.update_space</code>. That doesn't update the currently logged in user when an upload is destroyed.</p> <p>How do I achieve that ?</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