mercredi 28 juin 2017

First rails application: routes.rb not leading to right page(?)

Apologies in advance if this is so basic I probbaly shouldn't post it here. I'm not even sure if the title actually describes the issue. I am just starting to look at Ruby on Rails, and am following this page to set up "my first application": http://ift.tt/IsdtVd

Now, when I get to the point where I add

root 'welcome#index'

Into the routes.rb file and try and access it, it all goes wrong. First I thought it was a permissions issue, but I can access the views/layouts/welcome/index.html.erb file directly in the browser.

I'm so new to this that I haven't got far enough to know what I'm looking for in troubleshooting, hence this post.

When starting the rails server, I do get what looks like errors on restart and hangup signals, but I doubt this is the problem. Output listed here just in case.

=> Booting Puma
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> 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.9.1 (ruby 2.3.3-p222), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

Loading the root page gives the following server output:

Started GET "/" for 127.0.0.1 at 2017-06-28 13:17:23 +0200
Processing by WelcomeController#index as HTML
  Rendering welcome/index.html.erb within layouts/application
  Rendered welcome/index.html.erb within layouts/application (13.0ms)
Completed 500 Internal Server Error in 3742ms



ActionView::Template::Error (TypeError: Object doesn't support this property or method):
     5:
     6:     <%= csrf_meta_tags %>
     7:
     8:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
     9:     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    10:
    11:     </head>

app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb___750167210_57076860'

It kind of looks to me as though it does load the index page, but then something else triggers and it's redirected to a page that doesn't work. The content of the page it's directed to (views/layouts/application.html.erb) is:

<!DOCTYPE html>
<html>
  <head>
    <title>Blog</title>

    <%= csrf_meta_tags %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

    </head>

  <body>

    <%= yield %>

  </body>
</html>

Content of routes.rb for reference is:

Rails.application.routes.draw do
  get 'welcome/index'

  root 'welcome#index'

  # For details on the DSL available within this file, see http://ift.tt/GVpneB
end

Aucun commentaire:

Enregistrer un commentaire