soy nuevo en rails y estoy tratando de usar la FullCalendar y mysql como DB.
Al dar click en el caledario levanta un modal con un formulario y al dar click en un boton quiero guardar los datos via jquery ajax.
Pero no se estan pasando los parametros, solo inserta el campo por defecto created_at, pero los demas todos son NULL.
Este es el js:
$('#btnOK').on('click',function(){
var evento = $('#txtNombre').val();
var ini = $('#txtIni').val();
var fin = $('#txtFin').val();
$.ajax({
type: 'POST',
url: '/events/',
data: {event : {evento: evento,ini: ini,fin: fin}},
success: function(){
console.log('Datos guardados');
},
error: function(){
console.log('error ajax');
}
});
console.log(evento+' '+ini+' '+fin);
});
Controller generado con scaffold:
class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]
skip_before_action :verify_authenticity_token
# GET /events
# GET /events.json
def index
@events = Event.all
end
# GET /events/1
# GET /events/1.json
def show
end
# GET /events/new
def new
@event = Event.new
end
# GET /events/1/edit
def edit
end
# POST /events
# POST /events.json
def create
@event = Event.new(event_params)
respond_to do |format|
if @event.save
format.html { redirect_to @event, notice: 'Event was successfully created.' }
format.json { render :show, status: :created, location: @event }
else
format.html { render :new }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /events/1
# PATCH/PUT /events/1.json
def update
respond_to do |format|
if @event.update(event_params)
format.html { redirect_to @event, notice: 'Event was successfully updated.' }
format.json { render :show, status: :ok, location: @event }
else
format.html { render :edit }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
# DELETE /events/1
# DELETE /events/1.json
def destroy
@event.destroy
respond_to do |format|
format.html { redirect_to events_url, notice: 'Event was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def event_params
params.require(:event).permit(:title, :start, :end)
end
end
Alguna idea para arregarlo?
gracias