私は、私のレール4アプリでArticleというモデルを持っています。Rails 4 - ビューフォルダに静的なページを追加する方法
foldaway.html.erbという静的ページを自分のviews/articlesフォルダに追加したいとします。
私はそのビューのページを追加した、として、私の記事のコントローラを更新しました:私はまたset_articleメソッドから折りたたみ式を除外しようとしてい
def foldway
end
:私は私のルートファイルで
before_action :set_article, except: [:foldway], only: [:show, :edit, :update, :destroy ]
追加:
get '/foldway' => 'articles#foldway'
これをすべて保存してページがレンダリングされるかどうかをテストすると、
Couldn't find Article with 'id'=foldway
はなぜそれは私が私のレールコントローラでset_articleメソッドからそれを除外したときに文書番号を設定しようとしている。というエラートン。静的ページをレンダリングしたいだけです。
これをファイルに追加するにはどうすればよいですか?
私の完全な記事コントローラは次のとおりです。
class ArticlesController < ApplicationController
before_action :set_article, except: [:foldway], only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show ]
layout "article"
respond_to :html, :json
# GET /articles
# GET /articles.json
def index
@articles = policy_scope(Article)
# query = params[:query].presence || "*"
# @articles = Article.search(query)
end
# def index
# if params[:query].present?
# @books = Book.search(params[:query], page: params[:page])
# else
# @books = Book.all.page params[:page]
# end
# end
# GET /articles/1
# GET /articles/1.json
def show
end
def foldway
end
# GET /articles/new
def new
@article = Article.new
@article.comments.build
end
# GET /articles/1/edit
def edit
authorize @article
end
# POST /articles
# POST /articles.json
def create
# before_action :authenticate_user!
# authorize @article
@article = current_user.articles.new(article_params)
respond_to do |format|
if @article.save
format.html { redirect_to(@article) }
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
if @article.update(article_params)
format.html { redirect_to(@article) }
format.json { render :show, status: :ok, location: @article }
else
format.json { render json: @article.errors, status: :unprocessable_entity }
end
format.html { render :edit }
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])
authorize @article
end
# Never trust parameters from the scary internet, only allow the white list through.
def article_params
params.require(:article).permit(:body, :title, :image, :tag_list,
comment_attributes: [:opinion])
end
end
はあなたがあなたの完全なコントローラのコードを投稿してくださいすることができ:あなただけ配置する必要があります
とあなたの記事コントローラ用:
は、私はあなたがTUあなたのroutes.rbをファイルの中にこれを置く助言します記事? –
** only **を使用している場合は、** before ** action **の** **を必要としていますか? – dp7
それだけでは機能しないので、追加する以外は追加しました。 – Mel