简体   繁体   中英

Syntax Error in Controller#Index in Ruby on Rails

Im going to build an Ruby on Rails based Application with a little data base. But when I created the db with the scaffold tool I got an Syntax Error when I try to call the page via localhost:3000/informations .

On the top of the page:

SyntaxError in InformationsController#index

c:/anwendung/app/views/layouts/application.html.erb:24: syntax error, unexpected keyword_ensure, expecting keyword_end 
c:/anwendung/app/views/layouts/application.html.erb:26: syntax error, unexpected $end, expecting keyword_end

this is the code of application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>Anwendung</title>
  <% if mobile_device? %>
    <%= stylesheet_link_tag 'sencha-touch' %>
    <%= javascript_include_tag 'touch/sencha-touch' %>
    </head>
    <body>
    </body>
    </html>
  <% else %>
      <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
      <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>
</end>
</body>
</html>

It would be really nice if someone could help me with this.

You have missing <% end %> for your if-else condition. Also, HTML tags are not well paired.

Try this one:

<!DOCTYPE html>
<html>
<head>
  <title>Anwendung</title>
  <% if mobile_device? %>
    <%= stylesheet_link_tag 'sencha-touch' %>
    <%= javascript_include_tag 'touch/sencha-touch' %>
  <% else %>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
  <% end %>
</head>
<body>

<%= yield %>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM