update record by ajax - ruby-on-rails

I am showing a view where I show several records and I have a checkbox that I would like that when I change its value is sent via ajax the request to update the record, so far it works fine and updates, the problem is that when doing the respond_to still keeps the PATCH or PUT method to do the redirect. This is my checkbox:
<div class="form-check form-switch estado float-end">
<%= check_box_tag("reminder_status", value = "1", checked = #program.reminder.status, options = {id: "#{#program.reminder.id}", data_reminder_id: #program.reminder.id, class: 'form-check-input small toggle mt-2 mx-2 text-success', onchange: "reminder_status(this);"})%>
<%= label_tag "reminder_status", "#{t(:active)}", class: "form-control-placeholder pt-1 text-dark", id: "label_status" %>
</div>
<script type="text/javascript">
function reminder_status(chk) {
//function to update the completed field and mark the task as completed
$.ajax({
type: "PATCH",
url: "/programs/<%=#program.code%>/reminders/"+$(chk).attr('id'),
dataType: "script",
data: { reminder: {title : chk.checked} }
});
}
</script>
and this is the update method of reminders_controller:
def update
respond_to do |format|
if #reminder.update(reminder_params)
format.html { redirect_to show_program_client_path(#program.entity, program_id: #program.id, remove_modal: true), notice: "Reminders was successfully updated." }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: #reminder.errors, status: :unprocessable_entity }
end
end
end
and this is the result I get when I make some change in the check, first it is updating the reminder and it works fine but then when I do the respond_to it still keeps the PATCH method instead of GET for program when I just try to redirect.
Started PATCH "/programs/6xGUJq/reminders/161" for 127.0.0.1 at 2023-01-15 12:38:38 -0400
Processing by RemindersController#update as JS
Parameters: {"reminder"=>{"title"=>"false"}, "program_id"=>"6xGUJq", "id"=>"161"}
Program Load (0.4ms) SELECT "programs".* FROM "programs" WHERE "programs"."deleted_at" IS NULL AND "programs"."id" = $1 LIMIT $2 [["id", 175], ["LIMIT", 1]]
↳ app/controllers/reminders_controller.rb:107:in `set_program'
Reminder Load (0.3ms) SELECT "reminders".* FROM "reminders" WHERE "reminders"."deleted_at" IS NULL AND "reminders"."program_id" = $1 LIMIT $2 [["program_id", 175], ["LIMIT", 1]]
↳ app/controllers/reminders_controller.rb:103:in `set_reminder'
(0.1ms) BEGIN
↳ app/controllers/reminders_controller.rb:28:in `block in update'
Reminder Update (0.3ms) UPDATE "reminders" SET "title" = $1, "updated_at" = $2 WHERE "reminders"."id" = $3 [["title", "false"], ["updated_at", "2023-01-15 16:38:38.067467"], ["id", 161]]
↳ app/controllers/reminders_controller.rb:28:in `block in update'
(25.4ms) COMMIT
↳ app/controllers/reminders_controller.rb:28:in `block in update'
Client Load (0.4ms) SELECT "clients".* FROM "clients" WHERE "clients"."deleted_at" IS NULL AND "clients"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]]
↳ app/controllers/reminders_controller.rb:30:in `block (2 levels) in update'
Redirected to http://localhost:3000/clients/LM9UBL/show_program?program_id=175&remove_modal=true
Completed 302 Found in 35ms (ActiveRecord: 27.0ms | Allocations: 7281)
Started PATCH "/clients/LM9UBL/show_program?program_id=175&remove_modal=true" for 127.0.0.1 at 2023-01-15 12:38:38 -0400
ActionController::RoutingError (No route matches [PATCH] "/clients/LM9UBL/show_program"):
actionpack (6.0.4.8) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.4.8) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.4.8) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.4.8) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.4.8) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.4.8) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.4.8) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.4.8) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.4.8) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.4.8) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.4.8) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.4.8) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.4.8) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.4.8) lib/action_dispatch/middleware/host_authorization.rb:103:in `call'
webpacker (4.3.0) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.7.2) lib/rack/proxy.rb:67:in `call'
railties (6.0.4.8) lib/rails/engine.rb:527:in `call'
puma (4.3.12) lib/puma/configuration.rb:228:in `call'
puma (4.3.12) lib/puma/server.rb:727:in `handle_request'
puma (4.3.12) lib/puma/server.rb:476:in `process_client'
puma (4.3.12) lib/puma/server.rb:332:in `block in run'
puma (4.3.12) lib/puma/thread_pool.rb:134:in `block in spawn_thread'

Related

ActionController known Format

I am having an issue with this code. It is for uploading an audio file. When I upload it I get an error saying this:
ActionController::UnknownFormat at /users/1/audios/dfdfdsdsf ============================================================ > ActionController::UnknownFormat app/controllers/audios_controller.rb, line 67 --------------------------------------------- ``` ruby 62 if #audio.errors.empty? && #audio.update_attributes(update_audio_params) 63 respond_to do |format| 64 format.html { redirect_to user_audios_path(#user) } 65 end 66 else > 67 respond_to do |format| 68 format.html { render :edit } 69 format.js { render json: { result: :failed, errors: #audio.errors } } 70 end 71 end 72 end ``` App backtrace ------------- - app/controllers/audios_controller.rb:67:in `update' Full backtrace -------------- - actionpack (4.2.3) lib/action_controller/metal/mime_responds.rb:217:in `respond_to' - app/controllers/audios_controller.rb:67:in `update' - actionpack (4.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action' - actionpack (4.2.3) lib/abstract_controller/base.rb:198:in `process_action' - actionpack (4.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action' - actionpack (4.2.3) lib/abstract_controller/callbacks.rb:20:in `block in process_action' - activesupport (4.2.3) lib/active_support/callbacks.rb:115:in `call' - activesupport (4.2.3) lib/active_support/callbacks.rb:553:in `block (2 levels) in compile' - activesupport (4.2.3) lib/active_support/callbacks.rb:503:in `call' - activesupport (4.2.3) lib/active_support/callbacks.rb:88:in `run_callbacks' - actionpack (4.2.3) lib/abstract_controller/callbacks.rb:19:in `process_action' - actionpack (4.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action' - actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action' - activesupport (4.2.3) lib/active_support/notifications.rb:164:in `block in instrument' - activesupport (4.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument' - activesupport (4.2.3) lib/active_support/notifications.rb:164:in `instrument' - actionpack (4.2.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action' - actionpack (4.2.3) lib/action_controller/metal/params_wrapper.rb:250:in `process_action' - activerecord (4.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action' - actionpack (4.2.3) lib/abstract_controller/base.rb:137:in `process' - actionview (4.2.3) lib/action_view/rendering.rb:30:in `process' - rack-mini-profiler (0.9.8) lib/mini_profiler/profiling_methods.rb:106:in `block in profile_method' - actionpack (4.2.3) lib/action_controller/metal.rb:196:in `dispatch' - actionpack (4.2.3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' - actionpack (4.2.3) lib/action_controller/metal.rb:237:in `block in action' - actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:76:in `dispatch' - actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:45:in `serve' - actionpack (4.2.3) lib/action_dispatch/journey/router.rb:43:in `block in serve' - actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `serve' - actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:821:in `call' - warden (1.2.3) lib/warden/manager.rb:35:in `block in call' - warden (1.2.3) lib/warden/manager.rb:34:in `call' - rack (1.6.4) lib/rack/etag.rb:24:in `call' - rack (1.6.4) lib/rack/conditionalget.rb:38:in `call' - rack (1.6.4) lib/rack/head.rb:13:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:27:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/flash.rb:260:in `call' - rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context' - rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/cookies.rb:560:in `call' - activerecord (4.2.3) lib/active_record/query_cache.rb:36:in `call' - activerecord (4.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call' - activerecord (4.2.3) lib/active_record/migration.rb:377:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' - activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks' - actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call' - better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call' - better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call' - better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' - web-console (2.2.1) lib/web_console/middleware.rb:39:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' - railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app' - railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call' - activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged' - activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged' - activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged' - railties (4.2.3) lib/rails/rack/logger.rb:20:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call' - rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' - rack (1.6.4) lib/rack/runtime.rb:18:in `call' - activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' - rack (1.6.4) lib/rack/lock.rb:17:in `call' - actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call' - rack (1.6.4) lib/rack/sendfile.rb:113:in `call' - rack-mini-profiler (0.9.8) lib/mini_profiler/profiler.rb:282:in `call' - railties (4.2.3) lib/rails/engine.rb:518:in `call' - railties (4.2.3) lib/rails/application.rb:165:in `call' - rack (1.6.4) lib/rack/content_length.rb:15:in `call' - puma (2.12.2) lib/puma/server.rb:539:in `handle_request' - puma (2.12.2) lib/puma/server.rb:386:in `process_client' - puma (2.12.2) lib/puma/server.rb:269:in `block in run' - puma (2.12.2) lib/puma/thread_pool.rb:106:in `block in spawn_thread'
It might have to do with the respond_to block. Here is the code of that bellow:
def update
if params[:audio][:attachment].blank? && update_image_params.present?
#audio.update_audio_cover_picture update_image_params["photo"]
end
if #audio.errors.empty? && #audio.update_attributes(update_audio_params)
respond_to do |format|
format.html { redirect_to user_audios_path(#user) }
end
else
respond_to do |format|
format.html { render :edit }
format.js { render json: { result: :failed, errors: #audio.errors } }
end
end
end
This is a copy of the same code I use for my other project. It completely works on that app:
def update
if params[:book][:attachment].blank? && update_image_params.present?
#book.update_book_cover_picture update_image_params["photo"]
end
if #book.errors.empty? && #book.update_attributes(update_book_params)
respond_to do |format|
format.html { redirect_to user_books_path(#user) }
format.json { render json: { result: :success, url: user_books_url(#user) } }
end
else
respond_to do |format|
format.html { render :edit }
format.js { render json: { result: :failed, errors: #book.errors } }
end
end
end
From what your stack tells, it has something to do with the update method on your #audio. You are probably passing in weird parameters, or somehow filtering it incorrectly in your update_audio_params method.

How to validate a select_date in rails

Beginners in rails here, I try to allow the users to my company website to enter their birthdate with a date_select.
Everything works fine until I enter an invalid date such as the 31 of february. It gives me an argumentError saying that the date is invalid.
I'd like to catch the error without adding a gem to my config, but it's blurry to me and everything I tried during the last two days did not work.
This is my user.rb file
validate :ensure_birth_date_valid, if: lambda { mentee? && born_on.present? }
def ensure_birth_date_valid
Date.parse(born_on)
rescue
error.add(:born_on, :invalid)
end
Here is the form
<% if registration_for?(:mentee) %>
<div class="lobbyForm-group">
<%= f.label :born_on, class: 'lobbyForm-label' %>
<%= f.date_select :born_on, { :start_year => Date.today.year - Application::MENTEE_AGE_RANGE_MIN, :end_year => Date.today.year - Application::MENTEE_AGE_RANGE_MAX, :order => [:day, :month, :year], :prompt => true}, {:class => 'lobbyForm-control w-auto'} %>
</div>
<% end %>
Here is the code that transform the date_select into a date
def user_params
if params[:user]['born_on(1i)'].present? && params[:user]['born_on(2i)'].present? && params[:user]['born_on(3i)'].present?
date = Date.new params[:user]['born_on(1i)'].to_i, params[:user]['born_on(2i)'].to_i, params[:user]['born_on(3i)'].to_i
params[:user][:born_on] = date
end
permitted_params = [:first_name, :last_name, :email, :password, :password_confirmation, :born_on, :marketing_communications_accepted]
params.require(:user).permit(*permitted_params)
params[:user].merge mentee: true
end
Here is the full stack trace error
/work/academos/academos-plateforme-web/app/controllers/lobby/mentee_registrations_controller.rb:36:in `new'
/work/academos/academos-plateforme-web/app/controllers/lobby/mentee_registrations_controller.rb:36:in `user_params'
/work/academos/academos-plateforme-web/app/controllers/lobby/registrations_controller.rb:25:in `create'
/work/academos/academos-plateforme-web/app/controllers/lobby/mentee_registrations_controller.rb:12:in `create'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/base.rb:189:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:113:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:113:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:502:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:502:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:86:in `run_callbacks'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/callbacks.rb:19:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/notifications.rb:159:in `block in instrument'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/notifications.rb:159:in `instrument'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/abstract_controller/base.rb:136:in `process'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionview-4.1.11/lib/action_view/rendering.rb:30:in `process'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal.rb:196:in `dispatch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_controller/metal.rb:232:in `block in action'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:82:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:50:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/journey/router.rb:73:in `block in call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/journey/router.rb:59:in `each'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/journey/router.rb:59:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/routing/route_set.rb:692:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bullet-4.8.0/lib/bullet/rack.rb:10:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/error_collector.rb:50:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/agent_hooks.rb:26:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/etag.rb:23:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/conditionalget.rb:35:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/head.rb:11:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/flash.rb:254:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/session/abstract/id.rb:225:in `context'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/session/abstract/id.rb:220:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/cookies.rb:562:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/query_cache.rb:36:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.1.11/lib/active_record/migration.rb:380:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/callbacks.rb:82:in `run_callbacks'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/reloader.rb:73:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/rack/logger.rb:38:in `call_app'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/rack/logger.rb:22:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/methodoverride.rb:21:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/runtime.rb:17:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.1.11/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/lock.rb:17:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.1.11/lib/action_dispatch/middleware/static.rb:84:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.5.4/lib/rack/sendfile.rb:112:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sentry-raven-0.13.3/lib/raven/integrations/rack.rb:54:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/engine.rb:514:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.1.11/lib/rails/application.rb:144:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/newrelic_rpm-3.9.5.251/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/rack_patch.rb:13:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/configuration.rb:74:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/server.rb:492:in `handle_request'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/server.rb:363:in `process_client'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/server.rb:254:in `block in run'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/thread_pool.rb:101:in `call'
/home/jb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/puma-2.10.2/lib/puma/thread_pool.rb:101:in `block in spawn_thread'
Can anybody help?
Ok, I see. This is the problematic part:
date = Date.new params[:user]['born_on(1i)'].to_i, params[:user]['born_on(2i)'].to_i, params[:user]['born_on(3i)'].to_i
params[:user][:born_on] = date
You shouldn't be calling Date.new in the controller.
You can do something in the line of
date = "#{params[:user]['born_on(1i)'].to_i}-#{params[:user]['born_on(2i)'].to_i}-#{params[:user]['born_on(3i)'].to_i}"
params[:user][:born_on] = date
Now that you will have Date.parse('2016-02-31') and the errors can be added.

Koala::Facebook::AuthenticationError - type: OAuthException, code: 2500, message

I am trying to setup a project. Everything has gone fine but this error keeps prompting up and nothing seems to help. Here is the log when i hit the url.
Koala::Facebook::AuthenticationError - type: OAuthException, code: 2500, message: An active access token must be used to query information about the current user. [HTTP 400]:
koala (2.2.0) lib/koala/api/graph_api.rb:515:in `block in graph_call'
koala (2.2.0) lib/koala/api.rb:80:in `api'
koala (2.2.0) lib/koala/api/graph_api.rb:513:in `graph_call'
koala (2.2.0) lib/koala/api/graph_api.rb:115:in `get_connection'
() home/yogesh/Desktop/jugojuice/jugojuice/app/controllers/pages_controller.rb:98:in `show'
() home/yogesh/Desktop/jugojuice/jugojuice/app/controllers/pages_controller.rb:64:in `home'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:308:in `block (2 levels) in halting'
() home/yogesh/.rvm/gems/ruby-2.2.3/bundler/gems/route_translator-f00b46885426/lib/route_translator/extensions/action_controller.rb:20:in `set_locale_from_url'
activesupport (4.2.0) lib/active_support/callbacks.rb:427:in `block in make_lambda'
activesupport (4.2.0) lib/active_support/callbacks.rb:307:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
xray-rails (0.1.16) lib/xray/middleware.rb:37:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack-livereload (0.3.15) lib/rack/livereload.rb:23:in `_call'
rack-livereload (0.3.15) lib/rack/livereload.rb:14:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
() home/yogesh/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
() home/yogesh/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
() home/yogesh/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
logging (1.8.2) lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'
Started POST "/__better_errors/329b87011a8e5497/variables" for ::1 at 2015-11-18 16:48:21 +0530
My code in pages_controller.rb
class PagesController < ApplicationController
layout :determine_layout
before_filter :cms_setup, :only => [:show, :sitemap, :search]
before_filter :set_locale
helper_method :transformed_content
def parse_facebook_cookies
#facebook_cookies = Koala::Facebook::OAuth.new.get_user_info_from_cookie(cookies)
end
def sitemap
#page = Page.friendly.find("sitemap")
#subnav_pages = nil
end
def search
#page = Page.friendly.find("search")
#section = #page
#pages=Page.nested_set
#search = Sunspot.search([Cms::Page, Cms::Asset, Product, City, Location]) do
fulltext params[:terms] do
fields "title_#{I18n.locale}".to_sym, "content_#{I18n.locale}".to_sym, "description_#{I18n.locale}".to_sym, "address_#{I18n.locale}".to_sym
end
end
#results = #search.results
end
def cms_update
page = Page.find(params[:id])
region = Cms::Region.find(params[:region_id])
asset = Cms::Asset.find(params[:asset_id]) if params[:asset_id] && !params[:asset_id].blank?
# Update page
if asset
#asset.update_column(:content, params[:content])
if asset.content != params[:content]
asset.content = params[:content]
asset.save!
end
expire_fragment(["page_#{page.id}_region_#{region.id}_asset_#{asset.id}"])
else
asset = Cms::Asset.new(:content => params[:content], :name => "#{page.title} - #{region.name}")
asset.save
end
pra = Cms::PageRegionAsset.find_or_initialize_by(page_id: page.id, region_id: region.id, asset_id: asset.id) unless asset.nil?
unless params[:content].blank?
pra.save!
end
render text: ""
end
def home
response.headers.delete "X-Frame-Options"
#page = Page.root
get_site_pages
get_main_nav
get_subnav
#slides = Slide.visible.in_order
#newsletter_signup = NewsletterSignup.new
show
render "show"
end
def show
response.headers.delete "X-Frame-Options"
if #page.redirect_page_id.nil?
#get page template and regions
#template = #page.template
#regions = #template.regions
if #page.product_lines.any?
#product_line = #page.product_lines.first
end
if is_editing?
#page_content = HashWithIndifferentAccess[:regions => #regions.map { |r| {:placeholder => r.placeholder, :name => r.name, :id => r.id, :assets => r.serialized_assets_for(#page)}}.flatten]
else
#page_content = HashWithIndifferentAccess[:regions => #regions.map { |r|
{:placeholder => r.placeholder, :name => r.name, :id => r.id, :assets => r.serialized_assets_for(#page)}
}.flatten]
end
#cms_assets = #page.page_region_assets.order(position: :asc)
else
unless #page.redirect_page_id.nil?
#page = Page.find(#page.redirect_page_id)
redirect_to #page.menu_url and return
end
end
#instagram = Instagram.user_recent_media("2502342425320", {:count => 4})
#oauth = Koala::Facebook::OAuth.new("15239926112542342322478", "fc960a1a044492431aer35qafsd44a42c9c47990ef9b", "http://localhost:3000/")
#authtoken = #oauth.get_app_access_token
# generate authenticating URL
#graph = Koala::Facebook::API.new("1523992323611252478|1iBWrcRsYSBsISfsyUoNSmm_opxrI")
# #friends = #graph.get_connections("me", "friends")
# #profile = #graph.get_object("me")
#feed = #graph.get_connections("me", "feed")
end
def render_404
respond_to do |format|
format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
format.xml { head :not_found }
format.any { head :not_found }
end
end
private
def determine_layout
#page.template.file_name
end
def get_main_nav
#main_nav_items = Page.main_nav
end
def get_subnav
#subnav_pages = #page.subnav_pages
end
def get_site_pages
#site_pages = Page.nested_set.visible
end
def cms_setup
#render text: params.inspect and return
if params[:path].nil?
#page = Page.root
else
#page = Page.find_by_slug(params[:id]) if params[:id]
#page ||= Page.friendly.find(params[:path]) if params[:path]
#page ||= Page.root unless params[:path]
#page ||= Page.find_by(slug: params[:path].match(/[^\/]+$/)[0]) if params[:path]
#page ||= Page.find_by_slug("404")
if #page.nil?
#render text: params.inspect and return
render_404 and return
#page_not_found
redirect_to "/404" and return
end
end
#section = #page if #page.depth == 1
#section ||= #page.ancestors.select{|p| p.depth == 1}.first if #page.depth > 1
get_main_nav
get_subnav
end
def transformed_content(content)
frag = Nokogiri::HTML::fragment(content) #this gets us the regions content in a nodset
snippets = frag.css("div.cms-snippet")
dynamic_snippets = frag.xpath('descendant::div[#data-snippettype="dynamic"]')
dynamic_snippets.each do |ds|
object_class = ds.xpath("#data-objectclass")
object_id = ds.xpath("#data-objectid").first.value
snippet_partial = "/#{object_class.to_s.pluralize}/instance.html.haml"
ds.content = "" #zero out the content and replace it with a rendered partial
ds << (raw render :partial => snippet_partial, :locals => {:object_id => object_id}).to_s
end
frag
end
def page_params
params.require(:page).permit!
end
def page_not_found
raise ActionController::RoutingError.new('Not Found')
end
def set_locale
unless request.path.include?("/api")
#locale = params[:locale]
#locale ||= cookies[:locale]
#locale ||= I18n.default_locale
I18n.locale = #locale
if params[:locale].blank?
if cookies[:locale].blank?
redirect_to "/#{I18n.default_locale.to_s}#{request.path_info}" unless request.path.include?("/admin")
else
redirect_to "/#{cookies[:locale].to_s}#{request.path_info}" unless request.path.include?("/admin")
end
end
cookies[:locale] = I18n.locale
if request.path.include?("/admin")
I18n.locale = :en
end
end
end
end
I will be really thankful if someone tells me what is wrong here.
As #techdreams has commented, the error is the access token you're using, is invalid. Looking at your code seems you're getting the access token from a cookie. Just please keep in mind that an access token can become invalid if the user logs out of facebook or changes his/her password so you have always to implement a "refresh token" in your App, which basically is prompt the login dialog again to get a new token. If user has already approved your App this process will be transparent to him/her and they won't see the dialog again.

Rails 4 Boolean: Can't be set to true

I have a model with a boolean attribute "facturar" . I cannot set this attribute to true either through GUI or console. For some reason I can set it to false through console but not GUI. This happens if when I try to update any record of the model. Similar attribute "facturar_proveedor", also a boolean can be set to true or false in both GUI and console. What could cause this weird bug?
Pertinent Code
create_table "factura_items", force: :cascade do |t|
t.integer "factura_id"
t.integer "ordene_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "facturar"
t.integer "iva", limit: 8
t.integer "subtotal", limit: 8
t.boolean "facturar_proveedor"
t.integer "subcuenta_puc_id"
end
Controller
class FacturaItemsController < ApplicationController
before_action :set_factura_item, only: [:show, :edit, :update, :destroy]
# GET /factura_items
# GET /factura_items.json
def index
#search = FacturaItemSearch.new(params[:search])
authorize FacturaItem
#factura_items = #search.scope
#factura_items = FacturaItem.all
end
# GET /factura_items/1
# GET /factura_items/1.json
def show
#factura_items = FacturaItem.all
authorize #factura_item
#ordene = Ordene.all
#medio = Medio.all
end
# GET /factura_items/new
def new
#factura_item = FacturaItem.new
authorize #factura_item
end
# GET /factura_items/1/edit
def edit
authorize #factura_item
end
# POST /factura_items
# POST /factura_items.json
def create
#factura_item = FacturaItem.new(factura_item_params)
authorize #factura_item
#ordenes = Ordene.all
#medio = Medio.all
respond_to do |format|
if #factura_item.save
format.html { redirect_to #factura_item, notice: 'Factura item was successfully created.' }
format.json { render :show, status: :created, location: #factura_item }
else
format.html { render :new }
format.json { render json: #factura_item.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /factura_items/1
# PATCH/PUT /factura_items/1.json
def update
respond_to do |format|
authorize #factura_item
if #factura_item.update(factura_item_params)
format.html { redirect_to #factura_item, notice: 'Item de factura asociado con factura.' }
format.json { render :show, status: :ok, location: #factura_item }
else
format.html { render :edit }
format.json { render json: #factura_item.errors, status: :unprocessable_entity }
end
end
end
# DELETE /factura_items/1
# DELETE /factura_items/1.json
def destroy
#factura_item.destroy
authorize #factura_item
respond_to do |format|
format.html { redirect_to factura_items_url, notice: 'Factura item was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_factura_item
#factura_item = FacturaItem.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def factura_item_params
params.require(:factura_item).permit(:factura_id, :ordene_id, :medio_id, :revisado, :fecha_orden, :medida, :unidad, :costo_unidad, :total, :facturar, :cantidad, :facturar_proveedor, :sin_iva, :subcuenta_puc_id)
end
end
Edit Form
<% content_for :title do %>Factura Item<% end %>
<h3>Asignar Item a Factura</h3>
<div class="form">
<%= simple_form_for #factura_item do |form| %>
<%= form.input :facturar, label: 'Facturar a Cliente' %>
<%= form.input :facturar_proveedor, label: 'Facturar a Proveedor' %>
<%= form.input :sin_iva %>
<%= form.association :factura, :label_method => :id, include_blank: true, label: "Factura" %>
<%= form.button :submit, 'Guardar', class: 'submit' %>
<% end %>
</div>
<%= link_to 'Regresar', factura_items_path %>
POST logs
Started GET "/factura_items/1/edit" for ::1 at 2015-10-26 22:10:57 -0500
Processing by FacturaItemsController#edit as HTML
Parameters: {"id"=>"1"}
FacturaItem Load (0.3ms) SELECT "factura_items".* FROM "factura_items" WHERE "factura_items"."id" = $1 LIMIT 1 [["id", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Factura Load (0.8ms) SELECT "facturas".* FROM "facturas"
Rendered factura_items/edit.html.erb within layouts/application (47.8ms)
Rendered layouts/_navigation_links.html.erb (2.2ms)
Rendered layouts/_navigation.html.erb (3.7ms)
Rendered layouts/_messages.html.erb (0.1ms)
Completed 200 OK in 410ms (Views: 403.8ms | ActiveRecord: 2.6ms)
Started PATCH "/factura_items/1" for ::1 at 2015-10-26 22:11:36 -0500
Processing by FacturaItemsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"r1IUDwfqd4U48wvc07dSUjCI2ki/iQfHEu7QMr9peNIaDPimLqCVX6HPjCV+pytGOwV4jW1FSSguFK71g+re0g==", "factura_item"=>{"facturar"=>"1", "facturar_proveedor"=>"0", "sin_iva"=>"0", "factura_id"=>"1"}, "commit"=>"Guardar", "id"=>"1"}
FacturaItem Load (0.4ms) SELECT "factura_items".* FROM "factura_items" WHERE "factura_items"."id" = $1 LIMIT 1 [["id", 1]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
(0.2ms) BEGIN
(1.1ms) SELECT SUM("transaccions"."debito") FROM "transaccions"
SQL (2.5ms) INSERT INTO "transaccions" ("factura_item_id", "fecha", "debito", "subcuenta_puc_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["factura_item_id", 1], ["fecha", "2015-10-26"], ["debito", 1160000], ["subcuenta_puc_id", 128], ["created_at", "2015-10-27 03:11:36.359055"], ["updated_at", "2015-10-27 03:11:36.359055"]]
SQL (0.6ms) INSERT INTO "transaccions" ("factura_item_id", "fecha", "credito", "subcuenta_puc_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["factura_item_id", 1], ["fecha", "2015-10-26"], ["credito", 1000000], ["subcuenta_puc_id", 878], ["created_at", "2015-10-27 03:11:36.367100"], ["updated_at", "2015-10-27 03:11:36.367100"]]
SQL (0.7ms) INSERT INTO "transaccions" ("factura_item_id", "fecha", "credito", "subcuenta_puc_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["factura_item_id", 1], ["fecha", "2015-10-26"], ["credito", 160000], ["subcuenta_puc_id", 880], ["created_at", "2015-10-27 03:11:36.371111"], ["updated_at", "2015-10-27 03:11:36.371111"]]
Ordene Load (0.7ms) SELECT "ordenes".* FROM "ordenes" WHERE "ordenes"."id" = $1 LIMIT 1 [["id", 1]]
Medio Load (0.6ms) SELECT "medios".* FROM "medios" WHERE "medios"."id" = $1 LIMIT 1 [["id", 2]]
(1.8ms) COMMIT
Redirected to http://localhost:3000/factura_items/1
Completed 302 Found in 117ms (ActiveRecord: 16.2ms)
Started GET "/factura_items/1" for ::1 at 2015-10-26 22:11:36 -0500
Processing by FacturaItemsController#show as HTML
Parameters: {"id"=>"1"}
FacturaItem Load (0.5ms) SELECT "factura_items".* FROM "factura_items" WHERE "factura_items"."id" = $1 LIMIT 1 [["id", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Rendered factura_items/show.html.erb within layouts/application (4.0ms)
Completed 500 Internal Server Error in 14ms
NoMethodError - undefined method `id' for nil:NilClass:
app/views/factura_items/show.html.erb:3:in `_app_views_factura_items_show_html_erb__2824287575617260826_70230202524220'
actionview (4.2.0) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.0) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.0) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.0) lib/action_view/template.rb:143:in `render'
actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.0) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.0) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.0) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.0) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.0) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.0) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.0) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.0) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.0) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/davefogo/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.1.2) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/Users/davefogo/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/davefogo/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/davefogo/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Started POST "/__better_errors/726ca75c50ed7ed5/variables" for ::1 at 2015-10-26 22:11:36 -0500
FacturaItem Load (0.8ms) SELECT "factura_items".* FROM "factura_items"
Ordene Load (1.1ms) SELECT "ordenes".* FROM "ordenes"
Medio Load (1.6ms) SELECT "medios".* FROM "medio
Model
class FacturaItem < ActiveRecord::Base
belongs_to :factura
belongs_to :medio
belongs_to :ordene
belongs_to :subcuenta_puc
has_many :incentivos
before_save :calculate_total
around_update :generate_transaccion_facturar_cliente, :if => :facturar?
#running 1, 2 ,3 => before update, 4 => after_update OK
before_update :generate_transaccion_facturar_proveedor, :if => :facturar_proveedor?
after_update :generate_transaccion_incentivo_automatico, :if => :facturar?
def calculate_total
self.subtotal = (costo_unidad * cantidad) - (costo_unidad * descuento)
self.iva = (subtotal * 0.16)
self.total = subtotal + iva
end
def generate_transaccion_facturar_cliente
#This callback creates a activo transaccions for the facturacion to a cliente.
self.subcuenta_puc_id = 128
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, debito: self.total, subcuenta_puc_id: self.subcuenta_puc_id)
# generate_transaccion_facturar_cliente_pasivo
self.subcuenta_puc_id = 878
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, credito: self.subtotal, subcuenta_puc_id: self.subcuenta_puc_id)
#generate_transaccion_factura_cliente_iva
self.subcuenta_puc_id = 880
self.iva = 0 if self.sin_iva == true
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, credito: self.iva, subcuenta_puc_id: self.subcuenta_puc_id)
end
def generate_transaccion_facturar_proveedor
if cobro_proveedor == 'Facturacion'
#This callback creates an activo deudores transaccion for the facturacion to a proveedor for a incentivo.
self.subcuenta_puc_id = 129
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, debito: self.subtotal, subcuenta_puc_id: self.subcuenta_puc_id)
#generate_transaccion_factura_proveedor_iva
self.subcuenta_puc_id = 742
#if self.sin_iva == true
#self.iva = 0
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, credito: self.iva, subcuenta_puc_id: self.subcuenta_puc_id)
#Tgenerate_transaccion_facturar_proveedor_ingreso_operacional, his callback creates an ingreso operacional transaccion for the facturacion to a proveedor for a incentivo.
self.subcuenta_puc_id = 1232
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, credito: self.subtotal, subcuenta_puc_id: self.subcuenta_puc_id)
end
end
def generate_transaccion_incentivo_automatico
if ordene.medio.tipo_de_volumen == 'Automatico'
#This callback creates an activo incentivos por cruzar
self.subcuenta_puc_id = 130
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, debito: self.ordene.incentivo, subcuenta_puc_id: self.subcuenta_puc_id)
#This callback creates an ingreso operacional cruce, :generate_transaccion_incentivo_automatico_ingreso_operacional
self.subcuenta_puc_id = 1233
Transaccion.create!(factura_item_id: self.id, fecha: Time.now, credito: self.ordene.incentivo, subcuenta_puc_id: self.subcuenta_puc_id)
end
end
end
SOLUTION: I have modified the callbacks in the model. I removed the around_update callback and placed its contents in after_update.
Your logs for PATCH seems weird since it is not doing anything like:
UPDATE "factura_items" SET "facturar" = $1, "updated_at" = $2 WHERE "factura_items"."id" = $3
And there are lots of logs that are not produced by your controller update action behavior like:
(1.1ms) SELECT SUM("transaccions"."debito") FROM "transaccions"
SQL (2.5ms) INSERT INTO "transaccions" ("factura_item_id", "fecha", "debito", "subcuenta_puc_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["factura_item_id", 1], ["fecha", "2015-10-26"], ["debito", 1160000], ["subcuenta_puc_id", 128], ["created_at", "2015-10-27 03:11:36.359055"], ["updated_at", "2015-10-27 03:11:36.359055"]]
SQL (0.6ms) INSERT INTO "transaccions" ("factura_item_id", "fecha", "credito", "subcuenta_puc_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["factura_item_id", 1], ["fecha", "2015-10-26"], ["credito", 1000000], ["subcuenta_puc_id", 878], ["created_at", "2015-10-27 03:11:36.367100"], ["updated_at", "2015-10-27 03:11:36.367100"]]
SQL (0.7ms) INSERT INTO "transaccions" ("factura_item_id", "fecha", "credito", "subcuenta_puc_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["factura_item_id", 1], ["fecha", "2015-10-26"], ["credito", 160000], ["subcuenta_puc_id", 880], ["created_at", "2015-10-27 03:11:36.371111"], ["updated_at", "2015-10-27 03:11:36.371111"]]
SOLUTION: I have modified the callbacks in the model. I removed the around_update callback and placed its contents in after_update.

Why am I getting this TypeError? "no implicit conversion of Module into Integer"

I'm getting TypeError in CwIntegratorAccountsController#create. I'm calling a script (CwGetCompanyIntegrator.call) in the create method of the controller.
CwIntegratorAccountsController:
require 'apis/cw_get_company_integrator'
class CwIntegratorAccountsController < ApplicationController
skip_before_filter :require_company, :only => [:create,:new]
# GET /cw_integrator_accounts
# GET /cw_integrator_accounts.json
def create
unless CwIntegratorAccount.count >= 1
#cw_integrator_account = CwIntegratorAccount.new(params[:cw_integrator_account])
respond_to do |format|
if #cw_integrator_account.save
# Run the CW Integrator
CwGetCompanyIntegrator.call
format.html { redirect_to root_url, notice: 'cw_integrator success' }
#format.json { render json: #cw_integrator_account, status: :created, location: #cw_integrator_account }
else
format.html { render action: 'new' }
format.json { render json: #cw_integrator_account.errors, status: :unprocessable_entity }
end
end
end
end
end
It looks like it's failing when it starts the https request to the ConnectWise Server at this line: response = http.start {|h| h.request(request)}
CwGetCompanyIntegrator script:
#!/usr/bin/env ruby
require 'net/https'
require 'uri'
require 'nokogiri'
require 'apis/cw_apis'
class CwGetCompanyIntegrator
def self.call
cw_integrator_account = CwIntegratorAccount.first
cw_hostname = cw_integrator_account.cw_hostname
company_api_url = "https://#{cw_hostname}/v4_6_release/apis/2.0/CompanyApi.asmx"
uri = URI.parse(company_api_url)
request = Net::HTTP::Post.new(uri.path)
request.add_field('Content-Type', 'text/xml; charset=utf-8')
request.add_field('SOAPAction', 'http://connectwise.com/GetCompany')
request.body = CwApis.get_company_xml_request
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.start {|h| h.request(request)}
xml_doc = Nokogiri::XML(response.body).remove_namespaces!
company_name = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/CompanyName').text
company_street_addr = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/StreetLines/string')[0].text
begin
company_street_addr2 = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/StreetLines/string')[1].text
end
company_city = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/City').text
company_state = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/State').text
company_zip = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/Zip').text
company_country = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/Country').text
company_status = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/Status').text
company_phone = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/PhoneNumber').text
company_fax = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/FaxNumber').text
company_www = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/WebSite').text
CompanyInfosController.create!(cw_company_id: cw_integrator_account.cw_company_id, company_name: company_name,
company_street_addr: company_street_addr, company_street_addr2: company_street_addr2,
company_city: company_city, company_state: company_state, company_zip: company_zip,
company_country:company_country, company_status: company_status, company_phone: company_phone,
company_fax: company_fax, company_www: company_www)
end
end
This Class is called in the CwGetCompanyIntegrator script:
#!/usr/bin/env ruby
require 'builder'
class CwApis
def self.get_company_xml_request
cw_integrator_account = CwIntegratorAccount.first
integrator_company_id = cw_integrator_account.integrator_company_id
integrator_login_id = cw_integrator_account.integrator_login_id
integrator_password = cw_integrator_account.integrator_password
xml = Builder::XmlMarkup.new(:indent=>2)
xml.instruct!
xml.tag!('soap:Envelope',
:'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
:xmlns => 'http://connectwise.com'){
xml.tag!('soap:Body'){
xml.tag!('GetCompany'){
xml.tag!('credentials'){
xml.CompanyId(integrator_company_id)
xml.IntegratorLoginId(integrator_login_id)
xml.IntegratorPassword(integrator_password)
}
xml.id(cw_integrator_account.cw_company_id)
}
}
}
end
end
Full trace:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:893:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:893:in `new'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:893:in `connect'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:851:in `start'
lib/apis/cw_get_company_integrator.rb:21:in `call'
app/controllers/cw_integrator_accounts_controller.rb:54:in `block in create'
actionpack (3.2.14) lib/action_controller/metal/mime_responds.rb:270:in `call'
actionpack (3.2.14) lib/action_controller/metal/mime_responds.rb:270:in `retrieve_collector_from_mimes'
actionpack (3.2.14) lib/action_controller/metal/mime_responds.rb:194:in `respond_to'
app/controllers/cw_integrator_accounts_controller.rb:50:in `create'
actionpack (3.2.14) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.14) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.14) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.14) lib/active_support/callbacks.rb:447:in `_run__2237874046494148672__process_action__4163123032493016418__callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.14) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.14) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.14) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.14) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.14) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.14) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.14) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.14) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.14) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.14) lib/abstract_controller/rendering.rb:45:in `process'
rack-mini-profiler (0.9.2) lib/mini_profiler/profiling_methods.rb:108:in `block in profile_method'
actionpack (3.2.14) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.14) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.14) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.14) lib/action_dispatch/routing/route_set.rb:608:in `call'
rack-webconsole-pry (0.1.9) lib/rack/webconsole/assets.rb:26:in `call'
rack-webconsole-pry (0.1.9) lib/rack/webconsole.rb:79:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.14) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.14) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `_run__2942276951910103516__call__2669772965393719582__callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.14) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.14) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.14) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.14) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.14) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.14) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.14) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.14) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.14) lib/action_dispatch/middleware/static.rb:63:in `call'
rack-mini-profiler (0.9.2) lib/mini_profiler/profiler.rb:300:in `call'
railties (3.2.14) lib/rails/engine.rb:484:in `call'
railties (3.2.14) lib/rails/application.rb:231:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.14) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
This works in a plain ruby script, is it an environment thing?
Working Ruby Scripts:
CompanyApis class:
require 'builder'
class CompanyApis
def self.get_company
cw_company_id = 21920
integrator_company_id = 'COMPANY_ID'
integrator_login_id = 'INTERGRATOR_LOGIN'
integrator_password = 'INTERGRATOR_PW'
xml = Builder::XmlMarkup.new(:indent=>2)
xml.instruct!
xml.tag!('soap:Envelope',
:'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
:xmlns => 'http://connectwise.com'){
xml.tag!('soap:Body'){
xml.tag!('GetCompany'){
xml.tag!('credentials'){
xml.CompanyId(integrator_company_id)
xml.IntegratorLoginId(integrator_login_id)
xml.IntegratorPassword(integrator_password)
}
xml.id(cw_company_id)
}
}
}
end
end
CwIntegrator class:
require 'net/https'
require 'uri'
require 'nokogiri'
require './company_api'
class CwIntegrator
def self.call
cw_company_id = 21920
cw_hostname = 'cw.host.com'
companyapi_url = "https://#{cw_hostname}/v4_6_release/apis/2.0/CompanyApi.asmx"
uri = URI.parse(companyapi_url)
# Use for proxying to Kali
#proxy_addr = '172.16.1.149'
#proxy_port = 8080
request = Net::HTTP::Post.new(uri.path)
request.add_field('Content-Type', 'text/xml; charset=utf-8')
request.add_field('SOAPAction', 'http://connectwise.com/GetCompany')
request.body = CompanyApis.get_company
http = Net::HTTP.new(uri.host, uri.port)
# Use for proxying to Kali
#http = Net::HTTP.new(uri.host, uri.port, proxy_addr, proxy_port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.start {|h| h.request(request)}
company_info = []
xml_doc = Nokogiri::XML(response.body).remove_namespaces!
company_name = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/CompanyName').text
company_street_addr = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/StreetLines/string')[0].text
begin
company_street_addr2 = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/StreetLines/string')[1].text
end
company_city = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/City').text
company_state = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/State').text
company_zip = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/Zip').text
company_country = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/DefaultAddress/Country').text
company_status = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/Status').text
company_phone = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/PhoneNumber').text
company_fax = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/FaxNumber').text
company_www = xml_doc.xpath('//Envelope/Body/GetCompanyResponse/GetCompanyResult/WebSite').text
company_info += [company_name: company_name, cw_company_id: cw_company_id, company_name: company_name,
company_street_addr: company_street_addr, company_street_addr2: company_street_addr2,
company_city: company_city, company_state: company_state, company_zip: company_zip,
company_country:company_country,company_status: company_status, company_phone: company_phone,
company_fax: company_fax, company_www: company_www]
puts(company_info)
end
end
CwIntegrator.call
Rails is jealous and greedy to some methods like call etc. Probably simple renaming of the target method from call to neutral my_call would resolve the problem.
I bet there rails pretend to gain full power on call method, overriding it after your class is initialized.

Resources