简体   繁体   English

Ruby on Rails 4渲染部分不渲染

[英]Ruby on Rails 4 render partial does not render

It has been months I try to upgrade an old Rails 2.X webpage to Rails 4. I'm still struggling with some partial render views. 几个月以来,我一直试图将旧的Rails 2.X网页升级到Rails4。我仍在努力解决部分局部渲染视图的问题。 So I thought I could use some help. 所以我认为我可以使用一些帮助。 I've saved all my upgrade notes if it helps someone. 我已经保存了所有升级说明,如果有帮助的话。 But this one I cannot figure. 但是我无法确定这一点。

The current problem is that the following code prints only the address form (see the comment). 当前的问题是以下代码仅打印地址表单(请参见注释)。

views/users/_seller.erb: 视图/用户/_seller.erb:

<table class="labels">
<tr>
  <td>{Seller type}</td>
  <td><%= seller.select(:stype, ["producer","distributor","store"]) %></td>
</tr>
(...)
<h3>{Store/Pickup address}</h3>
<% seller.fields_for :address do |address_fields| %>
<!-- THIS IS NOT RENDERED!! -->
<table class="labels">
<tr>
  <td>{Address Line 1}</td>
  <td><%= address_fields.text_field :line1 %></td>
</tr>
<!-- UP TO THERE IS NOT RENDERED!! -->
<% end %>

This partial view is called by this one: views/users/create_seller.html.erb: 此部分视图由以下部分调用:views / users / create_seller.html.erb:

<h1>{Before you sell a product, please enter your seller information}</h1>

<%= form_for @seller, :url => "/seller/create" do |f| %>
  <h2>form</h2>
  <% @seller.errors.full_messages.each do |msg| %>
     <p><%= msg %></p>
  <% end %>
  <%= render partial: "seller", locals: {seller:f} %>
  <%= f.submit "Submit" %>
<% end %>

If you need to see my model. 如果您需要查看我的模型。 I presume it is good because it was working in older version: models/seller.rb 我认为这很好,因为它在较旧的版本中运行:models / seller.rb

class Seller < ActiveRecord::Base
  belongs_to :user

  belongs_to :address, :class_name => "Address", :foreign_key => 'address_id'
  accepts_nested_attributes_for :address, :allow_destroy => true
  belongs_to :shipping_address, :class_name => "Address", :foreign_key => 'shipping_address_id'
  accepts_nested_attributes_for :shipping_address, :allow_destroy => true
end

This is the controller code 这是控制器代码

controllers/users_controllers.rb controllers / users_controllers.rb

def create_seller #get
  @user = @current_user
  @seller = Seller.new
  @seller.tax1 = 500
  @seller.tax1_name_fr = "TPS"
  @seller.tax1_name_en = "GST"
  @seller.tax2 = 950
  @seller.tax2_name_fr = "TVQ"
  @seller.tax2_name_en = "QST"
  @seller.build_address
  @seller.build_shipping_address
end
<% seller.fields_for :address do |address_fields| %>

Should be 应该

<%= seller.fields_for :address do |address_fields| %>

Note the "=" symbol after the <% to show output I'm sure you already realise this but using the = sign in erb tags was a major change after version 2.xx 请注意<%后的“ =”符号以显示输出,我确定您已经意识到这一点,但是在版本2.xx之后,在erb标签中使用=符号是一项重大更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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