Rails 5.2不呈现新视图

时间:2018-03-24 11:50:20

标签: ruby-on-rails view ruby-on-rails-5 render ruby-on-rails-5.2

我有一个脚手架控制器。在状态中,当它被调用时它不呈现任何视图。如果我删除了@event = Event.new,则会调用我的视图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)

无视图渲染。

  # 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)

查看渲染。

更新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

1 个答案:

答案 0 :(得分:0)

行。我的事件模型的belongs_to :tap与tap()方法冲突。

解决。