I have a controller that was scaffold. In the state, when it is call it does not render any view. If I remove the @event = Event.new
, it calls my view new
.
# GET /admin/events/new
def new
@event = Event.new
end
Started GET "/admin/events/new" for 127.0.0.1 at 2018-03-24 12:35:21 +0100
Processing by Admin::EventsController#new as HTML
Admin Load (0.5ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = ? ORDER BY "admins"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
↳ /Users/florentbeaurain/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activerecord-5.2.0.rc1/lib/active_record/log_subscriber.rb:98
Completed 200 OK in 6208ms (ActiveRecord: 0.5ms)
No view rendering.
# GET /admin/events/new
def new
end
Started GET "/admin/events/new" for 127.0.0.1 at 2018-03-24 12:38:17 +0100
Processing by Admin::EventsController#new as HTML
Admin Load (0.2ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = ? ORDER BY "admins"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
↳ /Users/florentbeaurain/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activerecord-5.2.0.rc1/lib/active_record/log_subscriber.rb:98
Rendering admin/events/new.html.erb within layouts/admin
Rendered admin/events/_form.html.erb (2.9ms)
Rendered admin/events/new.html.erb within layouts/admin (5.0ms)
Completed 500 Internal Server Error in 27ms (ActiveRecord: 0.8ms)
View rendering.
UPDATE 1 :
class ApplicationController < ActionController::Base
end
class Admin::ApplicationController < ApplicationController
layout 'admin'
before_action :authenticate_admin!
end
class Admin::EventsController < Admin::ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]
# GET /events
def index
@events = Event.includes(:tap).all
end
# GET /events/1
def show
end
# GET /events/new
def new
@event = Event.new
end
# GET /events/1/edit
def edit
end
# POST /events
def create
@event = Event.new(event_params)
if @event.save
redirect_to admin_event_path(@event), notice: 'Event was successfully created.'
else
render :new
end
end
# PATCH/PUT /events/1
def update
if @event.update(event_params)
redirect_to admin_event_path(@event), notice: 'Event was successfully updated.'
else
render :edit
end
end
# DELETE /events/1
def destroy
@event.destroy
redirect_to admin_events_url, notice: 'Event was successfully destroyed.'
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(:tap_id, :kind)
end
end
OK. My Event model have a belongs_to :tap
which is in conflict with the tap() method.
Solved.