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. 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:
<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:
<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
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
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
Should be
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