我一直在使用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吗? –