Re: rails constantly failing with http 406 error

Walter Lee Davis <[email protected]> Sun, 28 Jul 2019 12:50:06 -0400
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
One thing I would definitely try, especially if this is your first time with RoR, is to use the built-in scaffold generator. It will show you what a canonical model, controller, and basic CRUD views look like. If you're trying to build a Welcome model and so forth, and you know what attributes a welcome has, then you can let scaffold build a "Belcome" model (or whatever deliberate mis-spelling makes you laugh) and see what's different between what Rails expects and you've built so far. Some of it will be obvious, some will be very subtle, but everything about the scaffold version will be canonically correct. Make sure you're in the top level of your project folder, and type:

bin/rails generate scaffold Belcome headline body:text

That will build you a belcome.rb model, a belcomes_controller.rb controller, a views/belcomes/index.html.erb, show.html.erb, edit.html.erb, create.html.erb, and _form.html.erb, a belcomes_helper.rb and a config/routes.rb entry for all of those. It will also create some JS and CSS assets and other bits I can't recall at the moment. If you haven't already, check your project into version control BEFORE you do this, so you can easily visualize the differences before and after.

As you continue your explorations, I cannot recommend enough the Rails Tutorial, available free at https://railstutorial.org -- we have all new employees at University of Pennsylvania use it as part of their training. It walks you through building a Twitter clone, from scratch. Along the way it explores all the major conventions of Rails programming -- why you do things a certain way, or not.

Walter

> On Jul 28, 2019, at 10:44 AM, Barry Kimelman <[email protected]> wrote:
> 
> The same error still occurs
> 
> 
> 
> C:\barry\ruby\environment\blog>ruby bin\rails server
> => Booting Puma
> => Rails 5.2.3 application starting in development
> => Run `rails server -h` for more startup options
> *** SIGUSR2 not implemented, signal based restart unavailable!
> *** SIGUSR1 not implemented, signal based restart unavailable!
> *** SIGHUP not implemented, signal based logs reopening unavailable!
> Puma starting in single mode...
> * Version 3.12.1 (ruby 2.6.0-p0), codename: Llamas in Pajamas
> * Min threads: 5, max threads: 5
> * Environment: development
> * Listening on tcp://localhost:3000
> Use Ctrl-C to stop
> C:/Ruby/lib/ruby/gems/2.6.0/gems/activemodel-5.2.3/lib/active_model/validations/clusivity.rb:8: warning: already initialized
> constant ActiveModel::Validations::Clusivity::ERROR_MESSAGE
> C:/ruby/lib/ruby/gems/2.6.0/gems/activemodel-5.2.3/lib/active_model/validations/clusivity.rb:8: warning: previous definition
> of ERROR_MESSAGE was here
> Started GET "/" for ::1 at 2019-07-28 08:41:42 -0600
> Processing by Rails::WelcomeController#index as HTML
> Completed 406 Not Acceptable in 436ms (ActiveRecord: 0.0ms)
> 
> 
> 
> ActionController::UnknownFormat (Rails::WelcomeController#index is missing a template for this request format and variant.
> 
> request.formats: ["text/html"]
> request.variant: []
> 
> NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you'
> re loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an e
> rror to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a
> shot.):
> 
> actionpack (5.2.3) lib/action_controller/metal/implicit_render.rb:55:in `default_render'
> actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
> actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
> actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
> actionpack (5.2.3) lib/abstract_controller/base.rb:194:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/rendering.rb:30:in `process_action'
> actionpack (5.2.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
> activesupport (5.2.3) lib/active_support/callbacks.rb:132:in `run_callbacks'
> actionpack (5.2.3) lib/abstract_controller/callbacks.rb:41:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/rescue.rb:22:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
> activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'
> activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
> activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'
> actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
> activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
> actionpack (5.2.3) lib/abstract_controller/base.rb:134:in `process'
> actionview (5.2.3) lib/action_view/rendering.rb:32:in `process'
> actionpack (5.2.3) lib/action_controller/metal.rb:191:in `dispatch'
> actionpack (5.2.3) lib/action_controller/metal.rb:252:in `dispatch'
> actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
> actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:34:in `serve'
> actionpack (5.2.3) lib/action_dispatch/journey/router.rb:52:in `block in serve'
> actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `each'
> actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `serve'
> actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:840:in `call'
> rack (2.0.7) lib/rack/tempfile_reaper.rb:15:in `call'
> rack (2.0.7) lib/rack/etag.rb:25:in `call'
> rack (2.0.7) lib/rack/conditional_get.rb:25:in `call'
> rack (2.0.7) lib/rack/head.rb:12:in `call'
> actionpack (5.2.3) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
> rack (2.0.7) lib/rack/session/abstract/id.rb:232:in `context'
> rack (2.0.7) lib/rack/session/abstract/id.rb:226:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/cookies.rb:670:in `call'
> activerecord (5.2.3) lib/active_record/migration.rb:559:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
> activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
> actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
> web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
> web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
> web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
> web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
> railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
> railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
> activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
> activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
> activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
> railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
> sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
> rack (2.0.7) lib/rack/method_override.rb:22:in `call'
> rack (2.0.7) lib/rack/runtime.rb:22:in `call'
> activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
> rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
> railties (5.2.3) lib/rails/engine.rb:524:in `call'
> puma (3.12.1) lib/puma/configuration.rb:227:in `call'
> puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
> puma (3.12.1) lib/puma/server.rb:474:in `process_client'
> puma (3.12.1) lib/puma/server.rb:334:in `block in run'
> puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
> 
> On Sun, Jul 28, 2019 at 7:07 AM Arun Kumar Nachimuthu <[email protected]> wrote:
> You would add content that you want to be displayed in the page. 
> 
> On Sun, Jul 28, 2019, 18:28 Barry Kimelman <[email protected]> wrote:
> Thanks for the reply,
> 
> My apps\views folder does not have a welcome subfolder !   What should I put in my app\views\welcome\index.html.erb file ?
> 
> On Sat, Jul 27, 2019 at 9:24 PM Arun Kumar Nachimuthu <[email protected]> wrote:
> Do you have a index.html.erb in the app/views/welcome folder? Create one if it doesn't exist. If that doesn't work, try renaming your controller to some word that can be pluralized. For ex, WelcomeMessageController and create index.html.erb in app/views/welcome_messages folder. 
> 
> On Sun, Jul 28, 2019, 02:37 Barry Kimelman <[email protected]> wrote:
> I am a ruby and rails rookie just trying to give myself an intro to ruby and rails on my windows 10 laptop.
> 
> Almost everything I try with rails ends up failing with a "http 406" error. I did some research on http 406 error and what I found stated "data was requested in a format not supported by the server".
> 
> I was just following the simple steps in a rails beginner tutorial to create a basic "blog" application. I changed to the directory where I wanted the application structure to be created and issued the command "rails new blog". After that succeeded I changed the current directory to "blog". As stated in the tutorial I issued the command "ruby bin\rails server". I waited for the messages from the server yo be displayed which indicated the server was ready to accept requests. I then went into my browser and entered the URL http://localhost:3000. After a very short time the server displayed an error message and a traceback.
> 
> 
> 
> C:\barry\ruby\environment\blog>ruby bin\rails server
> => Booting Puma
> => Rails 5.2.3 application starting in development
> => Run `rails server -h` for more startup options
> *** SIGUSR2 not implemented, signal based restart unavailable!
> *** SIGUSR1 not implemented, signal based restart unavailable!
> *** SIGHUP not implemented, signal based logs reopening unavailable!
> Puma starting in single mode...
> * Version 3.12.1 (ruby 2.6.0-p0), codename: Llamas in Pajamas
> * Min threads: 5, max threads: 5
> * Environment: development
> * Listening on tcp://localhost:3000
> Use Ctrl-C to stop
> C:/Ruby/lib/ruby/gems/2.6.0/gems/activemodel-5.2.3/lib/active_model/validations/clusivity.rb:8: warning: already initialized
> constant ActiveModel::Validations::Clusivity::ERROR_MESSAGE
> C:/ruby/lib/ruby/gems/2.6.0/gems/activemodel-5.2.3/lib/active_model/validations/clusivity.rb:8: warning: previous definition
> of ERROR_MESSAGE was here
> Started GET "/" for ::1 at 2019-07-27 14:02:12 -0600
> Processing by Rails::WelcomeController#index as HTML
> Completed 406 Not Acceptable in 708ms (ActiveRecord: 0.0ms)
> 
> 
> 
> ActionController::UnknownFormat (Rails::WelcomeController#index is missing a template for this request format and variant.
> 
> request.formats: ["text/html"]
> request.variant: []
> 
> NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you'
> re loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an e
> rror to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a
> shot.):
> 
> actionpack (5.2.3) lib/action_controller/metal/implicit_render.rb:55:in `default_render'
> actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
> actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
> actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
> actionpack (5.2.3) lib/abstract_controller/base.rb:194:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/rendering.rb:30:in `process_action'
> actionpack (5.2.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
> activesupport (5.2.3) lib/active_support/callbacks.rb:132:in `run_callbacks'
> actionpack (5.2.3) lib/abstract_controller/callbacks.rb:41:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/rescue.rb:22:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
> activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'
> activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
> activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'
> actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
> actionpack (5.2.3) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
> activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
> actionpack (5.2.3) lib/abstract_controller/base.rb:134:in `process'
> actionview (5.2.3) lib/action_view/rendering.rb:32:in `process'
> actionpack (5.2.3) lib/action_controller/metal.rb:191:in `dispatch'
> actionpack (5.2.3) lib/action_controller/metal.rb:252:in `dispatch'
> actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
> actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:34:in `serve'
> actionpack (5.2.3) lib/action_dispatch/journey/router.rb:52:in `block in serve'
> actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `each'
> actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `serve'
> actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:840:in `call'
> rack (2.0.7) lib/rack/tempfile_reaper.rb:15:in `call'
> rack (2.0.7) lib/rack/etag.rb:25:in `call'
> rack (2.0.7) lib/rack/conditional_get.rb:25:in `call'
> rack (2.0.7) lib/rack/head.rb:12:in `call'
> actionpack (5.2.3) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
> rack (2.0.7) lib/rack/session/abstract/id.rb:232:in `context'
> rack (2.0.7) lib/rack/session/abstract/id.rb:226:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/cookies.rb:670:in `call'
> activerecord (5.2.3) lib/active_record/migration.rb:559:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
> activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
> actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
> web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
> web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
> web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
> web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
> railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
> railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
> activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
> activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
> activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
> railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
> sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
> rack (2.0.7) lib/rack/method_override.rb:22:in `call'
> rack (2.0.7) lib/rack/runtime.rb:22:in `call'
> activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
> actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
> rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
> railties (5.2.3) lib/rails/engine.rb:524:in `call'
> puma (3.12.1) lib/puma/configuration.rb:227:in `call'
> puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
> puma (3.12.1) lib/puma/server.rb:474:in `process_client'
> puma (3.12.1) lib/puma/server.rb:334:in `block in run'
> puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
> 
> 
> I noticed the text near the start of the error/traceback which said something about a missing template for this request. How can anything be missing at this point ?
> 
> Please help a desperate rails rookie.
> 
> Thanks.
> ==================
> 
> Barry Kimelman
> Winnipeg, Manitoba, Canada
> 
> 	Virus-free. www.avast.com
> 
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
> 
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
> 
> 
> -- 
> 
> ==================
> 
> Barry Kimelman
> Winnipeg, Manitoba, Canada
> 
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
> 
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
> 
> 
> -- 
> 
> ==================
> 
> Barry Kimelman
> Winnipeg, Manitoba, Canada
> 
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>