尝试通过这样做来渲染不同的布局:
class LocationsController < ApplicationController
render layout "locations"
在Layouts中有相应的locations.html.erb文件和包含索引和显示文件的Locations文件夹。
我的位置布局文件就是这样:
<!DOCTYPE html>
<html>
<head>
<title>locations layout</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="ui menu">
<%= link_to "Counties", counties_path, :class => "active item"%>
<%= link_to "About Us", about_path, :class => "item"%>
</div>
<%= yield %>
</body>
</html>
我收到此错误并且不知道原因:
undefined method `render' for LocationsController:Class
我的所有路由也都列在错误消息中,如下所示:
resources :counties do
resources :locations
end
root 'home#index'
get '/about' => "home#about"
get "/:location_name_with_prefix" => "locations#show_by_location_name"
答案 0 :(得分:0)
你应该只打电话
layout "locations"
所以,删除'render'
答案 1 :(得分:0)
无需放置render关键字。只能使用
layout 'locations'
它应该有效