i have rails 4 application showing odd behavior on live production site. when creating post, default rails timestamps (created_at , updated_at) being set nil, , way solve restart heroku dynos.
after restart heroku, can create posts again. post being created, timestamps set nil. when click 'create post', server throws 500 error because have code in post view comparing timestamps.
this never happens on local development environment, happens on live heroku server.
has experienced this? can error in code if works fine on local , 'heroku restart' fixes (temporarily)? app dangerously close memory maxing out, can have it?
here's post create definition:
def create @post = post.new(post_params) @post.user_id = current_user.id @post.user.increment!(:level, 20) if @post.save subscription.create(:user_id => current_user.id, :post_id => @post.id, :comments_count => 0, :updated_at => (time.now - 1.minute)) user.where(:auto_sub => true).each |user| unless user.id == current_user.id subscription.create(:post_id => @post.id, :user_id => user.id, :comments_count => 0, :updated_at => (time.now - 1.minute)) end end redirect_to @post, notice: "look @ you, you're @ internet thing" else render 'new' end end and here's show definition:
def show @post = post.friendly.find(params[:id]) @user = @post.user @other_posts = post.where(:blog => true).sample(4) if user_signed_in? @subscription = @post.subscriptions.where(:user_id => current_user.id) if @subscription.count > 0 if @post.comments_count > 0 @subscription.last.update_attributes(:updated_at => time.now, :comments_count => @post.comments_count, :last_comment_id => @post.comments.last.id) else @subscription.last.update_attributes(:updated_at => time.now, :comments_count => @post.comments_count) end end end @comments = @post.comments.paginate(:page => params[:page], :per_page => 20) redirect_to live_path if post.friendly.find(params[:id]).live == true end any ideas be?
setting post.record_timestamps = false stop updated_at , created_at being set on subsequent requests dyno (if have more 1 dyno, requests other dynos not affected until changed setting too).
a heroku restart fixes things because in freshly started app setting has not been changed - upvote , update actions. in development, either actions run, additionally development environment reloads automatically in response code changes.
you don't why set record_timestamps false should set true once you've done whatever requires setting. write method :
class post < activerecord::base def self.without_timestamps begin old_value = record_timestamps self.record_timestamps = false yield ensure self.record_timestamps = old_value end end end and use wrap blocks should run without timestamps.
Comments
Post a Comment