heroku error - NoMethodError (undefined method `updated?' - ruby-on-rails

I've a rails 3.1 app on Heroku, I keep getting an 500 error in production which I can't recreate in dev.
When I try to perform an update action in one of my controllers I get a 500. I get the following from heroku logs -
2011-12-05T13:52:35+00:00 app[web.1]: Completed 500 Internal Server Error in 15ms
2011-12-05T13:52:35+00:00 app[web.1]:
2011-12-05T13:52:35+00:00 app[web.1]: NoMethodError (undefined method `updated?' for #<ActiveRecord::Associations::HasOneAssociation:0x00000004058800>):
2011-12-05T13:52:35+00:00 app[web.1]: app/controllers/cars_controller.rb:81:in `block in update'
2011-12-05T13:52:35+00:00 app[web.1]: app/controllers/cars_controller.rb:80:in `update'
The update action on my cars controller is -
def update
#car = Car.find_by_url_identifier(params[:id])
respond_to do |format| #**line 80**
if #car.update_attributes(params[:car]) #**line 81**
CarMailer.gift_confirmation(#car).deliver
format.html { redirect_to(thanks_path(#car.url_identifier)) }
else
format.html { render action: "edit" }
end
end
end
The parameters being posted are -
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"RTXCVvdsKQHc8CxHLeYS9WuztcrI1b4H8SHsdfsKWu+Iz4=",
"car"=>{"name"=>"dgdfsdfsd",
"email"=>"test#test.com",
"recipient_attributes"=>{"name"=>"fdsfsd",
"address1"=>"sdfsdfdsf",
"address2"=>"dsfdsfsdf",
"city"=>"sdfdsf",
"postcode"=>"sdfds"},
"gift_id"=>"2",
"message"=>"fsdfsdfdsf",
"terms"=>"1"},
"commit"=>"submit",
"id"=>"test5"}
My car model looks like this -
class Car < ActiveRecord::Base
validates :name, :presence =>true, :on => :update
validates :url_identifier, :presence =>true, :on => :create
has_one :recipient
belongs_to :gift
accepts_nested_attributes_for :recipient
accepts_nested_attributes_for :gift
def to_param
self.url_identifier
end
end
Any idea how I can fix this? Apart from looking at herokus logs, how else can I debug this?
Oddly the app work for a while if I do a 'heroku restart'

I can't see anything wrong in the code. Since it works on your development machine, I am guessing it is something else. Some difference. Did you run your migrations on heroku?
After deploying on heroku, you have to run your migrations in a separate step. I am not sure if that would give this kind of error. Just guessing here.

I googled the error message. Have you had a look at this thread: http://ruby-forum.com/topic/81719 They had a similar problem and have posted their solution/hack. Might be worth a try.

It looks like you are trying to call the method update to an ActiveRecord::Associations object instead of (probably) the Car model, which is strange because you would think it would be fetched and called on the model if it isn't a method found in Arel.
You could try to debug this by using the production environment settings in your development environment by looking in config/enviroments/production.rb and using those settings for development.
You could also try and recreate the problem on heroku using heroku console

Related

uninitialized constant Formtastic::I18n::SCOPES

Rails 6.0.1, Puma 4.3.0, Devise 4.7.1, ActiveAdmin 2.4.0, Formtastic 3.1.5.
Once again I am creating a Rails application. Created the foundation. A couple of models. Made a simple front-end for them. Next install Devise, ActiveAdmin.
In general, nothing unusual. Locally everything works fine.
But on the server, some kind of nonsense began to happen with ActiveAdmin.
In general, the application on the server is working fine. Through the console, I can create all the data. These data are successfully displayed on the site.
But if I go into ActiveAdmin...
Dashboard page displayed successfully. But if I go to the index page of any entity, then I will get the following error (from the log):
2019-11-19T00:55:04.216309411Z app[web.1]: web| I, [2019-11-19T00:55:04.198819 #14] INFO -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7] Rendered vendor/bundle/ruby/2.5.0/gems/activeadmin-2.4.0/app/views/active_admin/resource/index.html.arb (Duration: 73.2ms | Allocations: 17729)
2019-11-19T00:55:04.216369240Z app[web.1]: web| I, [2019-11-19T00:55:04.199305 #14] INFO -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7] Completed 500 Internal Server Error in 86ms (ActiveRecord: 5.8ms | Allocations: 19675)
2019-11-19T00:55:04.216376506Z app[web.1]: web| F, [2019-11-19T00:55:04.203841 #14] FATAL -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7]
2019-11-19T00:55:04.216380926Z app[web.1]: web| [9ac98910-3a38-496d-9f5e-f276bc590ba7] ActionView::Template::Error (uninitialized constant Formtastic::I18n::SCOPES
2019-11-19T00:55:04.216385058Z app[web.1]: web| Did you mean? Sprockets):
2019-11-19T00:55:04.216388027Z app[web.1]: web| [9ac98910-3a38-496d-9f5e-f276bc590ba7] 1: insert_tag renderer_for(:index)
The entire log: https://pastebin.com/raw/buWSveBZ
Only one section for entities works - this is the show action. Only two actions for entities work - these are show and destroy. Everyone else catches the error that I showed above.
I absolutely don't understand what's the matter.
I successfully use the identical config/initializers/active_admin.rb file in two other Rails 6 applications. Below I will show an example of one of the file for ActiveAdmin:
# frozen_string_literal: true
ActiveAdmin.register User do
menu priority: 5
permit_params :email, :full_name, :roles, :password, :password_confirmation
remove_filter :users_roles
controller do
def find_resource
scoped_collection.find_by!(pkey: params[:id])
end
end
index do
selectable_column
id_column
column :pkey
column :email
column :full_name
column :roles
column :current_sign_in_at
column :sign_in_count
column :created_at
actions
end
form do |f|
f.inputs do
f.input :email
f.input :full_name
f.input :roles
f.input :password
f.input :password_confirmation
end
f.actions
end
end
I'm hope for your help.
For what it's worth, I have a rails 6 app that I hadn't touched in about a year and was getting a similar error despite never having an issue with my other rails app that I use regularly -- uninitialized constant Formtastic::Util
Commenter above's advice of running rails generate formtastic:install did the trick for me. Thanks!

Rails NoMethodError for Blog#create on Heroku, but not Localhost

I have an app with a basic blog structure. Creating new blogs works perfectly on localhost, but when I try to create a new blog on Heroku I get the following error in my logs:
2018-07-11T21:20:01.863867+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] Command :: file -b --mime '/tmp/819c55b783715f61a2656207b4852b5c20180711-4-140ohfr.jpg'
2018-07-11T21:20:01.872443+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] Completed 500 Internal Server Error in 38ms (ActiveRecord: 0.0ms)
2018-07-11T21:20:01.873180+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0]
2018-07-11T21:20:01.873253+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] NoMethodError (undefined method `[]=' for nil:NilClass):
2018-07-11T21:20:01.873285+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0]
2018-07-11T21:20:01.873329+00:00 app[web.1]: [2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0] app/controllers/blogs_controller.rb:48:in `create'
2018-07-11T21:20:01.874027+00:00 app[web.1]: 10.101.219.132 - - [11/Jul/2018:21:19:56 UTC] "POST /blogs HTTP/1.1" 500 1958
2018-07-11T21:20:01.874063+00:00 app[web.1]: http://www.linchpinrealty.com/blogs/new -> /blogs
2018-07-11T21:20:01.874816+00:00 heroku[router]: at=info method=POST path="/blogs" host=www.linchpinrealty.com request_id=2f20a9d7-e0f6-4ab9-b2ac-d6b3a08e8ed0 fwd="68.225.227.137" dyno=web.1 connect=0ms service=5463ms status=500 bytes=2235 protocol=http
My blogs#create method is decently simple:
def create
#pillars = Pillar.all
#blog = Blog.new(blog_params)
if current_user.id = 1
#blog.user_id = 2
else
#blog.user = current_user
end
if #blog.save
redirect_to #blog, notice: 'Blog was successfully created.'
else
render :new
end
end
And I have the following permissions:
private
# Use callbacks to share common setup or constraints between actions.
def set_blog
#blog = Blog.friendly.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def blog_params
params.require(:blog).permit(:title, :teaser, :body, :user_id, :image, :tag_list, :link_text, :link_filename, :pillars_id)
end
I'm not sure where things are going off the rails (no pun intended). I did see this question where the issue was a database issue. In which case, the only recent change I've made would be in my blogs#show method...even though I have no idea how that would prevent a blog from even saving in the database (which it doesn't):
def show
#pillars = Pillar.all
#pillar = Pillar.find_by(id: #blog.pillars_id)
#related = Blog.where(pillars_id: #blog.pillars_id).where.not(id: #blog.id).limit(4)
#comment = #blog.comments.build
#comments = Comment.where(blog_id: #blog.id, approved: true)
if current_user
#user = current_user
end
end
Can anyone see where I'm going wrong?
From the logs and the fact it's working fine on your localhost, it's probably an error to host your tmp image file.
You should take a look at these articles:
Rails Active storage on Heroku
Rails Active storage exemple on Heroku
Edit:
I just saw you get the same error without an image, but don't you set any default image ?
-> Could you post error logs without uploaded image ?
Edit2:
I went on your website, I updated an image on an existing blog post and it works so it's probably not linked to the image system.
Edit3:
After some tests on your websites, it's the tag_list field which is wrong: you can create some new blog post without tags but as soon as you insert some tags an error is raised.
Ps: Sorry I did not managed to get my tests deleted without routes
Have you checked your migrations on Heroku?

Ruby error with mailgun on heroku server

I'm trying to make a 'contact us' page on a heroku server using mailgun. I am fairly confident I set it up right (I'm being spoon fed this project by following upskillcources.com), but I keep getting this error anyways "We're sorry, but something went wrong."
Here is the heroku logs that seem applicable to me:
2017-05-05T06:16:10.020320+00:00 app[web.1]: WHERE a.attrelid = '"contacts"'::regclass
2017-05-05T06:16:10.020321+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped
2017-05-05T06:16:10.020322+00:00 app[web.1]: ORDER BY a.attnum
2017-05-05T06:16:10.020323+00:00 app[web.1]: ):
2017-05-05T06:16:10.020344+00:00 app[web.1]: F, [2017-05-05T06:16:10.020309 #4] FATAL -- : [2777b122-a496-4a3d-b6b7-08b32fc56cd4]
2017-05-05T06:16:10.020377+00:00 app[web.1]: F, [2017-05-05T06:16:10.020344 #4] FATAL -- : [2777b122-a496-4a3d-b6b7-08b32fc56cd4] app/controllers/contacts_controller.rb:3:in `new'
I have no idea what could be wrong with the code in the error logs, especially because I can see that the contacts_controller.rb file is identical to identical project codes found on the github's of multiple people using the same resource upskill resource.
class ContactsController < ApplicationController
def new
#contact = Contact.new
end
def create
#contact = Contact.new(contact_params)
if #contact.save
name = params[:contact][:name]
email = params[:contact][:email]
body = params[:contact][:comments]
ContactMailer.contact_email(name, email, body).deliver
flash[:success] = "Message sent."
redirect_to new_contant_path #this should be contact path I think, but a c9 error suggested this instead and wouldn't work without the change dispite it being different than the codes on github for the same project.
else
flash[:danger] = #contact.errors.full_messages.join(", ")
redirect_to new_contact_path
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
Please also let me know for future ref how I can be better/more specific at asking questions here, so sorry for how difficult I am making it, this is my first programming project beyond 'hello world' and a to do app, thanks so much for taking the time!
Your logs says that you don't have a table in database.
You need to create and run migration. Details here: http://edgeguides.rubyonrails.org/active_record_migrations.html
Also you need to remember that Heroku doesn't run migrations for your by default. So you will need to call heroku run rake db:migrate after deploying your code. But you can automate this process by adding release command to your Procfile. Detailed instruction here: http://aspiringwebdev.com/run-rails-migrations-automatically-on-heroku/

Silent ruby/rails failure causes it to consume all memory and crash the server

I have a very strange bug which I'm in need of some clue on. Consider this:
class ApplicationController < ActionController::Base
before_filter :set_timezone
def set_timezone
if logged_in?
Time.zone = current_user.time_zone
end
end
When PayPal tries to send a notification, it comes in like so:
Started POST "/ipn_subscription_notifications" for 173.0.82.126 at 2012-03-15 04:11:45 -0400
Processing by IpnSubscriptionNotificationsController#create as HTML
Parameters: {"txn_type"=>"subscr_signup", etc...
And here it gets hung up. Ruby begins chewing up memory until the machine crashes. This is the fix:
def set_timezone
if current_user
Time.zone = current_user.time_zone
end
end
Let's look at logged_in?:
module AuthenticatedSystem
def logged_in?
current_user ? true : false
end
Which is logically equivalent to the fix.
I suspect an error is being thrown and caught, and somebody is restarting the request process. AuthenticatedSystem is certainly suspect.
This does not happen in the development environment, it throws an error and returns 500:
Started POST "/ipn_subscription_notifications" for 127.0.0.1 at 2012-03-15 15:19:39 -0700
Processing by IpnSubscriptionNotificationsController#create as */*
Parameters: {"foobar"=>nil}
Completed 500 Internal Server Error in 9ms
NoMethodError (undefined method `logged_in?' for #<IpnSubscriptionNotificationsController:0xdfdaaf4>):
app/controllers/application_controller.rb:8:in `set_timezone'
Rendered /usr/local/rvm/gems/ruby-1.9.2-p180#ce2/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-p180#ce2/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-p180#ce2/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4.8ms)
[2012-03-15 15:19:40] ERROR Errno::ECONNRESET: Connection reset by peer
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Detecting such failures and handling them gracefully is my goal.
Any ideas? Can I instrument Passenger, or some other part of the Rails stack?
the error is undefined method logged_in? in your IpnSubscriptionNotificationsController, and this controller inherit from ApplicationController, are u sure include AuthenticatedSystem module in your ApplicationController, may be u can try this first
May be this does not resolve your problem, but you should use around_filter :set_timezone instead of before filter. Take a look at this: http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails#working_with_multiple_user_time_zones

Rails 3 - Delayed_Job (collectiveidea), trying to Delay Mailers - Error: NoMethodError (undefined method `delay' for UserMailer:Class)

I'm using the delayed_job gem here: https://github.com/collectiveidea/delayed_job
I have the following in an observer:
UserMailer.delay.msg_notification(record)
In user_mailer.rb
class UserMailer < ActionMailer::Base
...
def msg_notification(record)
mail(
:to => "#{record.user.email}",
:subject => "Notification"
)
end
..
end
But this errors with:
NoMethodError (undefined method `delay' for UserMailer:Class):
Any ideas? thanks
I've seen a problem like this on our Rails app (2.3.8, but the issue sounds the same). Basically, there are three ways to delay an action:
MyClass.delay.foo(arg)
Putting handle_asynchronously :foo in your class definition after the definition of foo
MyClass.send_later(:foo, arg)
For whatever reason, #3 was the only form that worked consistently across all our development machines. #1 died on our development server (Ubuntu); #2 on our designer's Mac. But #3 was fine.
Hope that helps!
Also check if you have restarted your server after the bundle install. That could be a issue too...

Resources