1

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
1
  • The partial does render, it's the fields_for that is not rendering, you should rename your question Commented Dec 22, 2016 at 5:52

1 Answer 1

2
<% 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

Sign up to request clarification or add additional context in comments.

1 Comment

I had realized for <% form_for ... %>, but never thought about <% object.fields_for ... %>. Thanks again!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.