У меня есть форма, где у меня есть таблица с флажками, чтобы выбирать строки и сохранять идентификаторы в моей БД.Сильные параметры: отсутствует хэш-пара или пустое значение
Но он бросает мне ошибку:
Param is missing or the value is empty: leadallocation"
Я пробовал разные способы, но все еще и не работают. Поэтому на данный момент я просто палочку, чтобы сохранить хэш в моем db. Благодарю.
# Never trust parameters from the scary internet, only allow the white list through.
def leadallocation_params
params.require(:leadallocation).permit(:campaign_id, :company_id, :user_id)
end
Параметры запроса:
{"utf8"=>"✓",
"authenticity_token"=>"GruGL758jT4FO+t/BTRGLrD2uCGOj/qUCrB5VswquzR9N7JZ/rouLmGZnTE7A+XTARiLwkOy1n3/zMqhzuenmg==",
"company_ids"=>["38",
"40"],
"commit"=>"Create Leadallocation"}
Контроллер
class LeadallocationsController < ApplicationController
before_action :set_leadallocation, only: [:show, :edit, :update, :destroy]
# GET /leadallocations
# GET /leadallocations.json
def complete
end
def index
@leadallocations = Leadallocation.all
end
# GET /leadallocations/1
# GET /leadallocations/1.json
def show
end
# GET /leadallocations/new
def new
@leadallocation = Leadallocation.new
@comps = Company.all
end
# GET /leadallocations/1/edit
def edit
end
# POST /leadallocations
# POST /leadallocations.json
def create
@leadallocation = Leadallocation.new(leadallocation_params)
@leadallocation.company_id = params[:company_ids]
respond_to do |format|
if @leadallocation.save
format.html { redirect_to @leadallocation, notice: 'Leadallocation was successfully created.' }
format.json { render :show, status: :created, location: @leadallocation }
else
format.html { render :new }
format.json { render json: @leadallocation.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /leadallocations/1
# PATCH/PUT /leadallocations/1.json
def update
respond_to do |format|
if @leadallocation.update(leadallocation_params)
format.html { redirect_to @leadallocation, notice: 'Leadallocation was successfully updated.' }
format.json { render :show, status: :ok, location: @leadallocation }
else
format.html { render :edit }
format.json { render json: @leadallocation.errors, status: :unprocessable_entity }
end
end
end
# DELETE /leadallocations/1
# DELETE /leadallocations/1.json
def destroy
@leadallocation.destroy
respond_to do |format|
format.html { redirect_to leadallocations_url, notice: 'Leadallocation was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_leadallocation
@leadallocation = Leadallocation.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def leadallocation_params
params.require(:leadallocation).permit(:campaign_id, :company_id, :user_id)
end
end
Модели
class Leadallocation < ActiveRecord::Base
belongs_to :campaign
belongs_to :company
belongs_to :user
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :activities
belongs_to :campaign
has_many :leadallocations
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
class Company < ActiveRecord::Base
belongs_to :campaign
has_many :subsidiaries
has_many :leadallocations
end
class Campaign < ActiveRecord::Base
belongs_to :client
has_many :leads
has_many :activities
has_many :contacts
has_many :users
has_many :leadallocations
end
routes.rb
resources :leadallocations
Вид
<h1>New Leadallocation</h1>
<p id="notice"><%= notice %></p>
<h1>Listing Companies</h1>
<%= simple_form_for(@leadallocation) do |f| %>
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Country</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @comps.each do |company| %>
<tr>
<td><%= check_box_tag "company_ids[]", company.id %></td>
<td><%= company.name %></td>
<td><%= company.country %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
<%= link_to 'Back', leadallocations_path %>