ruby - Rails: How to make private posts to be public after downgrading user's level? -


i new ror , in app, want make private posts public once users cancel paid service. in other words, user's private posts become public after user downgrades account level standard.

below how approach scenario:

subscriptionscontroller:

def downgrade     subscription = current_user.subscription      if subscription.delete       downgrade_user_to_standard       current_user_downgrade_posts       flash[:success] = "sorry see go."       redirect_to user_path(current_user)     else       flash[:error] = "can't downgrade @ moment."       redirect_to root_path     end   end 

applicationcontroller:

protected  def downgrade_user_to_standard      current_user.update_attributes(role: "standard")    end     def current_user_downgrade_posts     privateposts = current_user.posts.where(private: true)     privateposts.each |privatepost|       privatepost.posts_update_attributes(private: false)     end    end  

when tested on server , console, found private post created earlier not made public expected after downgrading premium user standard level. since there no error message when ran rails server, can point out me steps missed , how can make work?

thank in advance!

i don't think code should in controller well...

you should change:

privatepost.posts_update_attributes(private: false) 

with:

privatepost.update_attribute(:private, false) 

if don't care validations, callbacks , touch timestamps can remove loop , use:

current_user.posts.where(private: true).update_all(private: false)