خرید بک لینک

Vote count: 0

I am having issues understanding this.

What am I trying to accomplish?

  • Selected items in dropdown submitted to inventory.

  • Change the status of each item in a form in its own model.

Problem

  • I submit a form and the status of each item in the dropdown doesn't get submitted.

Any help would be appreciated.

Thanks in advance!

Form Code

<%= form_for(@inventory, html: {class: "form-horizontal"}) do |f| %>
  <% if @inventory.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@inventory.errors.count, "error") %> prohibited this inventory from being saved:</h2>

      <ul>
      <% @inventory.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="form-group">
    <%= f.label :tablet_id, "Tablet #", class: "col-md-2 control-label" %>
    <div class="col-md-4">
      <%= select("inventory", "tablet_id", Tablet.where("status = '1'").all.collect{ |t| [t.alias, t.id] }, {}, { class: "form-control"} ) %>
    </div>
  </div>

  <%= f.fields_for :tablet do |t| %>
    <%= t.hidden_field :status, value: 2 %>
  <% end %>

  <div class="form-group">
    <%= f.label :chauffeur_id, "Chauffeur #", class: "col-md-2 control-label" %>
    <div class="col-md-4">
      <%= select("inventory", "chauffeur_id", Chauffeur.where("status = '1'").all.collect{ |t| [t.chaufNum, t.id] }, {}, { class: "form-control"} ) %>
    </div>
  </div>

  <%= f.fields_for :chauffeur do |t| %>
    <%= t.hidden_field :status, value: 2 %>
  <% end %>

  <div class="form-group">
    <%= f.label :vehicle_id, "Vehicle #", class: "col-md-2 control-label" %>
    <div class="col-md-4">
      <%= select("inventory", "vehicle_id", Vehicle.where("status = '1'").all.collect{ |t| [t.vehNum, t.id] }, {}, { class: "form-control"} ) %>
    </div>
  </div>

  <%= f.fields_for :vehicle do |t| %>
    <%= t.hidden_field :status, value: 2 %>
  <% end %>

  <div class="form-group">
    <div class="col-md-2 col-md-offset-2">
      <%= f.submit class: "btn btn-sm btn-success" %>
    </div>
  </div>
<% end %>

Model (Inventory)

class Inventory < ActiveRecord::Base
  belongs_to :tablet
  belongs_to :chauffeur
  belongs_to :vehicle

  accepts_nested_attributes_for :tablet
  accepts_nested_attributes_for :chauffeur
  accepts_nested_attributes_for :vehicle

  has_paper_trail

  validates :tablet_id, :chauffeur_id, :vehicle_id, presence: true
  validates :tablet_id, :chauffeur_id, :vehicle_id, uniqueness: { message: " is already checked out." }

end

Inventory Controller

def inventory_params
    params.require(:inventory).permit(:tablet_id, :chauffeur_id, :vehicle_id, tablet_attributes: [:status], chauffeur_attributes: [:status], vehicle_attributes: [:status])
end

asked 57 secs ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 8 ارديبهشت 1395 ساعت: 3:23

صفحه بندی