私はいくつかの静的ページを接続しようとしていますが、私はRuby on Railsの新機能ですので、ルートを正しく定義する方法に問題があります。rails routes link_to specific controller actions
私はページ/ user_quiz_question.htmlにユーザーを送信し、current_question_index変数を初期化することになっているこのリンクを静的ページページ/ user_quiz_startあります
#views/pages/user_quiz_start.html.rb:
<%= link_to 'Start Quiz!', :controller => :pages, :action => :start_quiz %>
をしかし、私は"ActionController::UrlGenerationError in Pages#show"
取得 - >No route matches {:action=>"start_quiz", :controller=>"pages", :page=>"user_quiz_start"}
はここに私のコントローラと私のルートである:私は私のルートは矛盾していることを知っている
#pages_controller.rb:
def show
if valid_page?
render template: "pages/#{params[:page]}"
else
render file: "public/404.html", status: :not_found
end
end
def start_quiz
if @quiz_session.start!
redirect_to user_quiz_question_path, notice: 'Quiz has been started'
else
redirect_to :back, error: 'Quiz cannot be started'
end
end
#in the model quiz_session.rb:
def start!
self.current_question_index = 0
end
#routes.rb:
Rails.application.routes.draw do
...
get 'home/index'
get '/user_quiz_start', :to => redirect('pages/user_quiz_start.html')
get '/user_quiz_question' => redirect('pages/user_quiz_question.html')
# Setup static pages
get "/pages/:page" => "pages#show"
devise_scope :user do
root to: redirect('/pages/user_home')
match '/sessions/user', to: 'devise/sessions#create', via: :post
end
root 'pages#home'
end
と私はレールのルートに関するさまざまなガイドを見てきましたが、私はまだそれを取得していません:/任意の助けをいただければ幸いです。
に
start_quiz
アクションに行くことができますありがとうございます!それは理にかなっている :) – megahra