Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to convert unpermitted parameters to hash - Ruby on Rails app error

I don't even know where to start with this... been trying to figure it out all day. Nothing relevant on google. My previously fine, entire site is unusable. Any page I go to throws the error "unable to convert unpermitted parameters to hash"

The better errors gem shows me:

Override to prevent #cause resetting during re-raise.

      attr_reader :cause
   def initialize(template)
        super($!.message)
        set_backtrace($!.backtrace)
    @cause = $!
    @template, @sub_templates = template, nil
  end

I had upgraded to Rails 5 earlier in the day, in completely the same way as with other Rails apps and had no problem at all - they all use more or less the same gems as well. I may be missing something but I can't even find the slightest clue of what's causing this. Any help would be amazing! Thanks! Please let me know if you require anything else.

Gemfile:

source 'https://rubygems.org'
ruby '2.4.1'

gem 'rails', '>= 5.0.0.rc2', '< 5.1'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem 'sass-rails', '~> 5.0', '>= 5.0.5'
gem 'therubyracer', '~> 0.12.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'jbuilder'
gem 'sdoc', '0.4.0', group: :doc
gem 'animate-rails'
gem 'google-analytics-rails', '1.1.0'
gem 'font-awesome-rails'
gem 'high_voltage', '~> 3.0.0'
gem 'sprockets-rails', require: 'sprockets/railtie'
gem 'simple_form'
gem 'pg', '~> 0.20.0'
gem 'canonical-rails', github: 'jumph4x/canonical-rails'
gem 'sitemap_generator'
gem 'fog'
gem 'listen', '~> 3.0'
gem 'devise', '~> 4.2'
gem 'paperclip'
gem 'aws-sdk', '~> 2.3'
gem 'wicked'
gem 'reform'
gem 'reform-rails'
gem 'binding_of_caller'
gem 'bootstrap-datepicker-rails'
gem 'exception_notification'
gem 'jquery-tablesorter'
gem 'friendly_id', '~> 5.1.0'
gem 'will_paginate', '~> 3.1.0'
gem 'sidekiq'
gem 'redis'
gem 'twilio-ruby'
gem 'phony_rails'
gem 'social-share-button'
gem 'chosen-rails'
gem 'respond-js-rails'

group :development, :test do
  gem 'byebug'
  gem 'better_errors'
  gem 'letter_opener'
  gem 'dotenv-rails'
  gem 'rspec-rails'
  gem 'factory_girl_rails'
end

group :development do
  gem 'spring'
  gem 'web-console'
end

group :test do
  gem 'minitest-reporters', '1.0.5'
  gem 'mini_backtrace',     '0.1.3'
  gem 'guard-minitest',     '2.3.1'
  gem 'faker'
  gem 'capybara'
  gem 'guard-rspec'
  gem 'launchy'
end

group :production do
  gem 'rails_12factor', '~> 0.0.3'
  gem 'puma',           '~> 3.8.2'
  gem 'heroku-deflater'
end

gem 'redactor-rails', github: 'glyph-fr/redactor-rails'

Relevant part of Error Logs:

actionpack (5.1.0.rc2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.0.rc2) lib/action_dispatch/middleware/static.rb:125:in `call'
() Users/luisaczc/.rvm/gems/ruby-2.4.1@global/gems/rack-        2.0.1/lib/rack/sendfile.rb:111:in `call'
railties (5.1.0.rc2) lib/rails/engine.rb:522:in `call'
puma (3.8.2) lib/puma/configuration.rb:224:in `call'
puma (3.8.2) lib/puma/server.rb:600:in `handle_request'
puma (3.8.2) lib/puma/server.rb:435:in `process_client'
puma (3.8.2) lib/puma/server.rb:299:in `block in run'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'


ActionView::Template::Error - unable to convert unpermitted parameters to     hash:
actionview (5.1.0.rc2) lib/action_view/template/error.rb:67:in `initialize'
actionview (5.1.0.rc2) lib/action_view/template.rb:321:in `handle_render_error'
actionview (5.1.0.rc2) lib/action_view/template.rb:160:in `rescue in render'
actionview (5.1.0.rc2) lib/action_view/template.rb:155:in `render'
actionview (5.1.0.rc2) lib/action_view/renderer/template_renderer.rb:64:in `render_with_layout'
actionview (5.1.0.rc2) lib/action_view/renderer/template_renderer.rb:50:in `render_template'
actionview (5.1.0.rc2) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (5.1.0.rc2) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (5.1.0.rc2) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (5.1.0.rc2) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.1.0.rc2) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (5.1.0.rc2) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (5.1.0.rc2) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.1.0.rc2) lib/action_controller/metal/renderers.rb:141:in `render_to_body'
actionpack (5.1.0.rc2) lib/abstract_controller/rendering.rb:24:in `render'
actionpack (5.1.0.rc2) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.1.0.rc2) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'

Just to reiterate - this isn't page specific, it's happening throughout. Normally I could follow a controller etc. and solve the problem but I'm completely lost on this.

like image 278
DanRio Avatar asked Apr 21 '17 20:04

DanRio


1 Answers

In rails 5.1 it looks like you have to permit access to the parameters if you want to convert the params object into a hash.

There are two solutions AFAIK:

1) In your controller do this :

form = Form.new(params[:form].permit!)

2) Add this to your config/application.rb to disable strong parameters in rails (not usually advised) :

config.action_controller.permit_all_parameters = true
like image 74
cmrichards Avatar answered Sep 19 '22 07:09

cmrichards