Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The Seller Profile has one seller. I am trying to post the seller profile details and assigning the seller_id to the current_seller. I am however, running into this error. I don't understand why the error says missing parameter because it seems all the needed params have being provided.

Error is get is ActionController::ParameterMissing (param is missing or the value is empty: seller_profiles

def create
    @seller_profile = SellerProfile.new(seller_profile_params)
    @seller_profile.seller = current_seller

    respond_to do |format|
      if @seller_profile.save
        format.html { redirect_to root_path, notice: 'Seller profile was successfully created.' }
 
def seller_profile_params
      params.require(:seller_profile).permit(:first_name, :other_name, :last_name, :email)
    end
<%= form_tag seller_seller_profiles_path do |form| %>
  <% if seller_profile.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(seller_profile.errors.count, "error") %> prohibited this seller_profile from being saved:</h2>

      <ul>
        <% seller_profile.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= label_tag :first_name %>
    <%= text_field_tag :first_name %>
  </div>

  <div class="field">
    <%= label_tag :other_name %>
    <%= text_field_tag :other_name %>
  </div>

  <div class="field">
    <%= label_tag :last_name %>
    <%= text_field_tag :last_name %>
  </div>

  <div class="field">
    <%= label_tag :email %>
    <%= text_field_tag :email %>
  </div>

  <div class="actions">
    <%= submit_tag %>
  </div>
<% end %>

resources :sellers, only: [:new, :create, :show, :index, :destroy] do
    resources :seller_profiles
  end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should use the form_for or the form_with helpers instead of form_tag. Those helper methods will take care of adding the wrapping seller_profile key.

<%= form_for seller_profile do |form| %>
  <% if seller_profile.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(seller_profile.errors.count, "error") %> prohibited this seller_profile from being saved:</h2>

      <ul>
        <% seller_profile.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :first_name %>
    <%= form.text_field :first_name %>
  </div>

  <div class="field">
    <%= form.label :other_name %>
    <%= form.text_field :other_name %>
  </div>

  ... replicate the same change for the rest of the fields ...

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...