我创建了一个标题布局,当前它出现在我网站的每个页面上。我希望它在注册页面上消失(有多个徽标看起来很差)。
以下是我的注册页面的内容 /app/views/users/new.html.erb /
<%= provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
以下是 /app/views/layouts/applications.html.erb
的内容<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
<%= render 'layouts/header' %>
正在调用我想在注册页面上忽略的标题。
我不确定我是否需要在application.html.erb文件中放置<% if .... %>
语句,或者我是否可以忽略new.html.erb文件中的标题
答案 0 :(得分:1)
您可以合并content_for and a
yield
as described in the Ruby on Rails Guides on Nested Layouts. You would do something like this:
yield
In /app/views/layouts/applications.html.erb
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all" %>
<style type="text/css"><%= yield :stylesheets %></style>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<div id="header_id">
<%= render 'layouts/header' %>
</div>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
At the top of /app/views/users/new.html.erb
将包含标题的div作为唯一ID,然后将其替换为#header_id。这不是最优雅的解决方案,但它应该有效。