我一直在使用Rails腳手架來構建Rails 4應用程序。導軌 - 腳手架 - 控制器設置 - unknownFormat
我現在的問題是載列如下 - 走到哪當我嘗試和呈現的文章新頁面在我的應用程序:
ActionController::UnknownFormat
它引用在文章控制器創建操作(它提取這個錯誤的位置):
@article = Article.new(article_params)
respond_to do |format|
if @article.save
format.json { render :show, status: :created, location: @article }
else
我有一個文章控制器:
class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]
# respond_to :html
# GET /articles
# GET /articles.json
def index
@articles = Article.all
end
# GET /articles/1
# GET /articles/1.json
def show
end
# GET /articles/new
def new
@article = Article.new
end
# GET /articles/1/edit
def edit
end
# POST /articles
# POST /articles.json
def create
# before_action :authenticate_user!
# authorize @article
@article = Article.new(article_params)
respond_to do |format|
if @article.save
format.json { render :show, status: :created, location: @article }
else
format.html { render :new }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /articles/1
# PATCH/PUT /articles/1.json
def update
before_action :authenticate_user!
authorize @article
respond_to do |format|
if @article.update(article_params)
format.json { render :show, status: :ok, location: @article }
else
format.html { render :edit }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# DELETE /articles/1
# DELETE /articles/1.json
def destroy
before_action :authenticate_user!
authorize @article
@article.destroy
respond_to do |format|
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_article
@article = Article.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def article_params
params[:article].permit(:body, :title, :image,
comment_attributes: [:opinion])
end
end
我在控制器的最上面一行迴應了html。我不知道這是爲什麼或者做了什麼。我已經閱讀了其他問題,說你需要給它迴應的東西,或者使用響應者寶石。我不想要任何非凡的東西 - 我只想讓頁面呈現。
任何人都可以看到這裏有什麼問題嗎?
我不知道你在做什麼。這看起來像是一起製作和展示動作。你能提供更多細節嗎?你有意使用JSON嗎? –