The context of the question is as follows:
I generated the entity Cotizacions
, through scaffold
. The corresponding view, model and controller was created: quote_controller.rb , quote.rb and views ( _cotizacion.json.jbuilder , _form.html.erb , edit.html.erb , index.html.erb , new.html.erb ).
Template, creative of Bootstrap is installed. Driver and corresponding views are created: creatives_controller.rb and views ( index.html.erb , _header.html.erb , etc.).
The first thing that was done was to occupy the generated form in the view of cotizacions
_form.html.erb . From the view it is creatives
file _header.html.erb , using the following code:
<header>
<div class="header-content">
<div class="header-content-inner">
<h1>Negocia tu Auto</h1>
<p>Somos una empresa especialista......</p>
<%= render :partial =>'cotizacions/form' , locals: { cotizacion:@cotizacion } %>
</div>
</div>
</header>
The problem is that when I trigger the event from the view cotizacions
, I receive the following message:
ActionController :: ParameterMissing in CotizacionsController # create param is missing or the value is empty: quote
The cotizacions
controller is as follows:
class CotizacionsController < ApplicationController
before_action :set_cotizacion, only: [:show, :edit, :update, :destroy]
def index
@cotizacions = Cotizacion.all
end
def show
end
def new
@cotizacion = Cotizacion.new
end
def edit
end
def create
@cotizacion = Cotizacion.new(cotizacion_params)
respond_to do |format|
if @cotizacion.save
format.html { redirect_to @cotizacion, notice: 'Cotizacion was successfully created.' }
format.json { render :show, status: :created, location: @cotizacion }
else
format.html { render :new }
format.json { render json: @cotizacion.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @cotizacion.update(cotizacion_params)
format.html { redirect_to @cotizacion, notice: 'Cotizacion was successfully updated.' }
format.json { render :show, status: :ok, location: @cotizacion }
else
format.html { render :edit }
format.json { render json: @cotizacion.errors, status: :unprocessable_entity }
end
end
end
def destroy
@cotizacion.destroy
respond_to do |format|
format.html { redirect_to cotizacions_url, notice: 'Cotizacion was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_cotizacion
@cotizacion = Cotizacion.find(params[:id])
end
def cotizacion_params
params.require(:cotizacion).permit(
:patente, :marca, :modelo, :kilometraje, :correo, :telefono, :comentarios,
:abs, :aire_acondicionado, :airbag, :cant, :velocidad_crucero, :aux, :aux1
)
end
end
I have tried to correct the problem by adding the following code to the creatives
driver;
class CreativesController < ApplicationController
layout "creative"
match "/cotizacions" => "cotizacions#create", :via => [:post]
end
But now I get the following error:
undefined method 'match' for CreativesController: Class Did you mean? catch
_form.html.erb:
<%= form_with(model: cotizacion) do |form| %>
<div class="container">
<div class="row">
<div class="col-md-2">
<div class="field">
<%= form.text_field :patente,
placeholder: "Patente",
id: :car_patente,
class: "form-control" %>
</div>
</div>
<div class="col-md-2">
<div class="form-inline">
<%= form.select :marca,
options_for_select([["SUBARU", "t"], ["KIA", "s"]], id: :car_marca),
prompt: "Marca",
class: "combobox form-control",
name: "inline"%>
</div>
</div>
<div class="col-md-2">
<div class="field">
<%= form.text_field :modelo,
id: :car_modelo,
placeholder: "Modelo Ej: Yaris, i10",
class: "form-control" %>
</div>
</div>
<div class="col-md-2">
<div class="field">
<%= form.select :kilometraje,
options_for_select([["0 - 10.0000", "t"], ["10.0001 - 20.0000", "s"]], id: :car_kilometraje),
prompt: "Kilometraje",
class: "combobox form-control",
name: "inline" %>
</div>
</div>
<div class="col-md-2">
<div class="field">
<%= form.email_field :correo,
id: :car_correo,
placeholder: "[email protected]",
class: "form-control" %>
</div>
</div>
<div class="col-md-2">
<div class="field">
<%= form.telephone_field :telefono,
id: :car_telefono,
placeholder: "Télefono",
class: "form-control" %>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<h2 class="text-center">Seleccione Equipamiento</h2>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon">
<%= form.check_box :abs, id: :car_abs %>
</span>
<input type="text" class="form-control" aria-label="...", placeholder="ABS">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon">
<%= form.check_box :aire_acondicionado, id: :car_aire_acondicionado %>
</span>
<input type="text" class="form-control" aria-label="...", placeholder="Aire Acondicionado">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon">
<%= form.check_box :airbag, id: :car_airbag %>
</span>
<input type="text" class="form-control" aria-label="...", placeholder="Airbag">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon">
<%= form.check_box :velocidad_crucero, id: :car_velocidad_crucero %>
</span>
<input type="text" class="form-control" aria-label="...", placeholder="Velocidad Crucero">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div>
</div>
<div class="row">
<div class="col-md-12 col-md-offset">
<div class="actions">
<%= form.submit class: 'btn btn-success btn-lg', value: 'Tasar su Vehículo' %>
</div>
</div>
</div>
</div>
<% end %>
routes.rb:
Rails.application.routes.draw do
get 'creatives/index'
resources :cotizacions
post 'creatives/index', to: 'cotizacions#create
end
log:
ActionController::ParameterMissing (param is missing or the value is empty: cotizacion):
app/controllers/cotizacions_controller.rb:74:in 'cotizacion_params'
app/controllers/cotizacions_controller.rb:29:in 'create'
Started POST "/creatives/index" for 127.0.0.1 at 2017-07-29 15:01:27 -0400
Processing by CotizacionsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"vu6ARii6s6IjRMeN7TWM1vmh/KKNja5l37EFnlfN7B0YtwvVq/bzIb9qbYTRuJDh8FwuZCgu1u2dvD4B0BPlog==", "patente"=>"", "marca"=>"", "modelo"=>"", "kilometraje"=>"", "correo"=>"", "telefono"=>"", "abs"=>"0", "aire_acondicionado"=>"0", "airbag"=>"0", "velocidad_crucero"=>"0", "commit"=>"Tasar su Vehículo"}
Completed 400 Bad Request in 1ms
ActionController::ParameterMissing (param is missing or the value is empty: cotizacion):
app/controllers/cotizacions_controller.rb:74:in 'cotizacion_params'
app/controllers/cotizacions_controller.rb:29:in 'create'
Started POST "/creatives/index" for 127.0.0.1 at 2017-07-29 15:01:28 -0400
Processing by CotizacionsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"vu6ARii6s6IjRMeN7TWM1vmh/KKNja5l37EFnlfN7B0YtwvVq/bzIb9qbYTRuJDh8FwuZCgu1u2dvD4B0BPlog==", "patente"=>"", "marca"=>"", "modelo"=>"", "kilometraje"=>"", "correo"=>"", "telefono"=>"", "abs"=>"0", "aire_acondicionado"=>"0", "airbag"=>"0", "velocidad_crucero"=>"0", "commit"=>"Tasar su Vehículo"}
Completed 400 Bad Request in 1ms