1

저는 Michael Hartl의 Ruby on Rails 튜토리얼을 따라 갔고 템플릿을 사용하여 응용 프로그램의 연락처 페이지를 만들었습니다. 그러나 양식 메서드가있는 연락처 페이지를 추가하고 싶습니다. 동일한 페이지에서 Hartl과 동일한 정적 페이지 컨트롤러를 사용합니다. 내 연락처 페이지를 작동시켜야합니다.Ruby on Rails - 정적 페이지 문의 양식

<h1>Contact us</h1> 

<%= form_for @page, url: static_pages_contact_path do |f| %> 

    <p> 
    <%= f.label :title %> 
    <%= f.text_field :title %> 
    </p> 

    <p> 
    <%= f.label :email %> 
    <%= f.text_area :email %> 
    </p> 

    <%= f.submit 'Send message' %> 

<% end %> 

첫 번째 행에 포함되는 오류 메시지에는 아무 것도 없거나 이와 같을 수 없습니다. 기록을 위해, 여기 내 정적 페이지 컨트롤러입니다. 레이크 경로를 실행

class StaticPagesController < ApplicationController 

    def show 
    @page = StaticPage.find(params[:id]) 
    end 

    def new 
    @page = Page.new 
    end 

    def create 
    @page = Page.find(params[:page]) 
    end 
end 

Prefix Verb URI Pattern      Controller#Action 
     users_new GET /users/new(.:format)   users#new 
    favorite_game PUT /games/:id/favorite(.:format) games#favorite 
      games GET /games(.:format)    games#index 
       POST /games(.:format)    games#create 
     new_game GET /games/new(.:format)   games#new 
     edit_game GET /games/:id/edit(.:format)  games#edit 
      game GET /games/:id(.:format)   games#show 
       PATCH /games/:id(.:format)   games#update 
       PUT /games/:id(.:format)   games#update 
       DELETE /games/:id(.:format)   games#destroy 
      users GET /users(.:format)    users#index 
       POST /users(.:format)    users#create 
     new_user GET /users/new(.:format)   users#new 
     edit_user GET /users/:id/edit(.:format)  users#edit 
      user GET /users/:id(.:format)   users#show 
       PATCH /users/:id(.:format)   users#update 
       PUT /users/:id(.:format)   users#update 
       DELETE /users/:id(.:format)   users#destroy 
     sessions POST /sessions(.:format)    sessions#create 
    new_session GET /sessions/new(.:format)   sessions#new 
     session DELETE /sessions/:id(.:format)   sessions#destroy 
users_favorites GET /users/favorites(.:format)  users#favorites 
static_pages_about GET /static_pages/about(.:format) static_pages#about 
static_pages_contact GET /static_pages/contact(.:format) static_pages#contact 
static_pages_help GET /static_pages/help(.:format) static_pages#help 
      signup GET /signup(.:format)    users#new 
      signin GET /signin(.:format)    sessions#new 
     signout DELETE /signout(.:format)    sessions#destroy 

나는 그게 내가 필요로하는 모든 정보 생각이다.

+0

우리는 특정 오류를 게시하는 것이 가장 좋습니다! –

답변

0

예를 들어 static_pages_contact_path은 아무 것도 할 수 없다고 생각합니다. 나는 당신이 리소스가 많은 라우팅을 통해 생성 된 경로를 참조하려고한다고 생각합니다. 당신은 (절대적이거나 상대적인) URL을 시도해 볼 수도 있고, 한 방법 또는 다른 방법으로 풍부한 라우팅을 사용할 수도 있습니다. 그러나 컨트롤러는 리소스가 아닙니다.

0

당신이있어 문제는 다음과 같다 :

-

을 POST

귀하의 routesstatic_pages_contactGET 요청으로 정의 가지고 만있다

귀하의 form 원하는 것 POST 요청을 제출해야합니다. 요청한 경로가 없으므로 다시 오류가 발생합니다. 자고. 이 문제를 해결하는 방법은 두 가지입니다 -

  1. routes
  2. 이 수정 컨트롤러에 대응하는 조치를 만들기 현재 컨트롤러 문제에 POST 요청을 만들기
#config/routes.rb 
resources :static_pages, only: [] do 
    collection do 
     get :about, action: "show" 
     get :help, action: "show" 
     get :contact, action: "show" 
     post :contact_submit 
    end 
end 

#app/controllers/static_pages_controller.rb 
class StaticPagesController < ApplicationController 
    def contact_submit 
    ... perform form submit here 
    end 
end 

그러면 문제가 해결됩니다.