iFurniture iFurniture - 2 months ago 9
Ruby Question

Rails - in `private': nil is not a symbo l (TypeError)

it appears in the production server, while in local server it not appears, the issue is in the Subscribe_Controller, there I define what parameters are sent to MailChimp for the mailing list , here is the error log from

$heroku run rails console
.

/app/app/controllers/subscribe_controller.rb:11:in `private': nil is not a symbo
l (TypeError)
from /app/app/controllers/subscribe_controller.rb:11:in `<class:Subscrib
eController>'
from /app/app/controllers/subscribe_controller.rb:1:in `<top (required)>
'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:274:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:274:in `block in require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:240:in `load_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:274:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:360:in `require_or_load'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:317:in `depend_on'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:233:in `require_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/engin
e.rb:472:in `block (2 levels) in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/engin
e.rb:471:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/engin
e.rb:471:in `block in eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/engin
e.rb:469:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/engin
e.rb:469:in `eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/engin
e.rb:346:in `eager_load!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/appli
cation/finisher.rb:56:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/appli
cation/finisher.rb:56:in `block in <module:Finisher>'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:30:in `instance_exec'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:30:in `run'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:55:in `block in run_initializers'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:in `block in tso
rt_each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:in `block (2 lev
els) in each_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:210:in `block (2 lev
els) in each_strongly_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:210:in `block (2 lev
els) in each_strongly_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:210:in `block (2 lev
els) in each_strongly_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:in `each_strongl
y_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:209:in `block in eac
h_strongly_connected_component_from'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:44:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:44:in `tsort_each_child'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:203:in `each_strongl
y_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:209:in `block in eac
h_strongly_connected_component_from'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:44:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:44:in `tsort_each_child'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:203:in `each_strongl
y_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:209:in `block in eac
h_strongly_connected_component_from'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:44:in `each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:44:in `tsort_each_child'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:203:in `each_strongl
y_connected_component_from'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:in `block in eac
h_strongly_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongl
y_connected_component'
from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/initi
alizable.rb:54:in `run_initializers'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/appli
cation.rb:352:in `initialize!'
from /app/config/environment.rb:5:in `<top (required)>'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:274:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:274:in `block in require'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:240:in `load_dependency'
from /app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.7.1/lib/active
_support/dependencies.rb:274:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/appli
cation.rb:328:in `require_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/comma
nds/commands_tasks.rb:142:in `require_application_and_environment!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/comma
nds/commands_tasks.rb:67:in `console'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/comma
nds/commands_tasks.rb:39:in `run_command!'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.7.1/lib/rails/comma
nds.rb:17:in `<top (required)>'
from /app/bin/rails:4:in `require'
from /app/bin/rails:4:in `<main>'


here is the log from the production server:

2016-09-21T14:53:45.788249+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.ifurniture.pe request_id=4e9cd392-23bb-4160-8f2b-e9886cf25016 fwd="190.234.106.227" dyno= connect= service= status=503 bytes=


this is the Subscribe_Controller.rb file..

class SubscribeController < ApplicationController
def create
logger.info "suscripcion #{params.inspect}"
user = user_params(params)
MailchimpWrapper.subscribe(user, params[:group_name], params[:group])
redirect_to '/gracias'
rescue Mailchimp::Error => e
logger.error "ERROR mailchimp #{e.message} #{params.inspect}"
end

private def user_params(params)
user = {
email: params[:email].try(:downcase),
first_name: params[:first_name].try(:titleize),
last_name: params[:last_name].try(:titleize),
city: params[:city].try(:titleize),
phone: params[:phone],
comment: params[:comment].try(:titleize)
}
user
end
end


I define the method in a new line like this..

private
def user_params(params)
user = {
email: params[:email].try(:downcase),
first_name: params[:first_name].try(:titleize),
last_name: params[:last_name].try(:titleize),
city: params[:city].try(:titleize),
phone: params[:phone],
comment: params[:comment].try(:titleize)
}
user
end
end


and get this error in production server...

2016-09-21T15:28:29.628087+00:00 app[web.1]: Started POST "/suscribir" for 190.234.106.227 at 2016-09-21 15:28:29 +0000

2016-09-21T15:28:29.635751+00:00 app[web.1]: Processing by SubscribeController#create as HTML

2016-09-21T15:28:29.635762+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"5sO+oVCDUD949rHpZz4RSxnSqpfXGZ9p9XwF+NO6HOkYPpfB95v1Wrn6EgxR7N+rEpVHOHuRtEaBAhNmoWTYVA==", "group_name"=>"suscriptores", "group"=>"newsletter", "email"=>"henry07_03@hotmail.com", "commit"=>"SUSCRIBIRSE"}

2016-09-21T15:28:29.635763+00:00 app[web.1]: suscripcion {"utf8"=>"✓", "authenticity_token"=>"5sO+oVCDUD949rHpZz4RSxnSqpfXGZ9p9XwF+NO6HOkYPpfB95v1Wrn6EgxR7N+rEpVHOHuRtEaBAhNmoWTYVA==", "group_name"=>"suscriptores", "group"=>"newsletter", "email"=>"henry07_03@hotmail.com", "commit"=>"SUSCRIBIRSE", "controller"=>"subscribe", "action"=>"create"}

2016-09-21T15:28:29.638002+00:00 app[web.1]: ERROR mailchimp You must provide a MailChimp API key {"utf8"=>"✓", "authenticity_token"=>"5sO+oVCDUD949rHpZz4RSxnSqpfXGZ9p9XwF+NO6HOkYPpfB95v1Wrn6EgxR7N+rEpVHOHuRtEaBAhNmoWTYVA==", "group_name"=>"suscriptores", "group"=>"newsletter", "email"=>"henry07_03@hotmail.com", "commit"=>"SUSCRIBIRSE", "controller"=>"subscribe", "action"=>"create"}

2016-09-21T15:28:29.657213+00:00 app[web.1]: [1m[35mRefinery::Page Load (0.8ms)[0m SELECT "refinery_pages".* FROM "refinery_pages" WHERE "refinery_pages"."menu_match" = $1 ORDER BY "refinery_pages"."id" ASC LIMIT 1 [["menu_match", "^/404$"]]

2016-09-21T15:28:29.661415+00:00 app[web.1]: [1m[36mRefinery::PagePart Load (2.1ms)[0m [1mSELECT "refinery_page_parts".* FROM "refinery_page_parts" WHERE "refinery_page_parts"."refinery_page_id" IN (2) ORDER BY position ASC[0m


I'll be attentive to your answers.

Answer

I belive You need your method on a new line after you call private:

private 

  def user_params(params)
    user = {
      email: params[:email].try(:downcase),
      first_name: params[:first_name].try(:titleize),
      last_name: params[:last_name].try(:titleize),
      city: params[:city].try(:titleize),
      phone: params[:phone],
      comment: params[:comment].try(:titleize)
    }
    user
  end