几个月来,我尝试将旧的Rails 2.X网页升级到Rails 4。 我仍在努力处理一些部分渲染视图。所以我想我可以用一些帮助。如果它有帮助,我已保存了我upgrade notes的所有内容。但这个我无法想象。
目前的问题是以下代码仅打印地址表单(请参阅注释)。
视图/用户/ _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 %>
此部分视图由以下部分调用: 视图/用户/ 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 %>
如果你需要看我的模特。我认为它很好,因为它在旧版本中工作: 模型/ 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
这是控制器代码
控制器/ 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
答案 0 :(得分:2)
<% seller.fields_for :address do |address_fields| %>
应该是
<%= seller.fields_for :address do |address_fields| %>
请注意<%
之后的“=”符号以显示输出我确定您已经意识到这一点,但在版本2.xx后使用erb标签中的=符号是一个重大更改