나는 날짜별로 구성된 게시물과 임의로 구성된 정보 페이지로 구성된 꽤 전형적인 블로그 사이트를 운영하고 있습니다. 주요 블로그 섹션 (posts#index
)은 잘 렌더링되지만, 은 마치 match '/info'
규칙이 제대로 감지되지 않는 것처럼 최상위 템플릿을 대신 렌더링합니다 (경로와 동일).레일 컨트롤러 렌더링 잘못된보기
나는 모두 동일한 레이아웃 (application.html.haml
)을 사용하고 있음을 이해합니다. 그러나 /posts
경로가 posts/index.html.haml
템플릿을 올바르게 표시하고있는 반면 /pages
경로는 으로 표시 될 때 application/index.html.haml
으로 표시됩니다.
컨트롤러가 명시 적으로 index
동작을 정의합니다. 그게 문제의 일부인지 확실하지 않지만, 동안 posts#index
이 잘 작동하는 이유는 무엇입니까?
routes.rb :
Foo::Application.routes.draw do
root :to => 'application#index'
match '/blog' => 'posts#index'
match '/info' => 'pages#index'
end
컨트롤러 :
# application_controller.rb
class ApplicationController < ActionController::Base
def show_tag
@tag = params[:tag]
end
end
# posts_controller.rb
class PostsController < ApplicationController
def show
@date = params[:date]
end
end
# pages_controller.rb
class PagesController < ApplicationController
def show
@title = params[:title]
end
end
... 그리고 전망 :
# layouts/index.html.haml
!!!
%html
%head
%title Foo
%meta{:charset => "utf-8"}
%meta{"http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1"}
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"}
= stylesheet_link_tag :application, :media => "all"
= javascript_include_tag :application
= csrf_meta_tags
%body
#container.container
%header
%h1
= link_to("Home", root_path)
#main{:role => "main"}
= yield
%footer
# application/index.html.haml
%p
%a{:href => 'blog'} Blog
%p
%a{:href => 'info'} Info
# posts/index.html.haml
%p List of blog posts
%ul
%li
%a{:href => 'blog/6-1'} June 1st
%li
%a{:href => 'blog/6-2'} June 2nd
# pages/index.html.haml
%p Info about stuff
%ul
%li
%a{:href => 'info/foo'} Foo
%li
%a{:href => 'info/bar'} Bar
내가 레일 3.2.13과 루비 1.9.3을 실행하는거야 . 미리 감사드립니다.
'application # index'에 관해서는 routes.rb에 넣는 것이 더 일반적일까요? 어쨌든 동일한 ** 레이아웃 **을 사용한다는 사실은 정확하게 문제가 아닙니다. 그것보다 더 미세한 입자입니다. :) 나는 (희망을 갖고) 명확히하기 위해 그 포스트를 편집했다. – acobster
@acobster 우리는 어떤 장소에도'application # index'를 넣지 않습니다. 그것은'routes.rb'에서 필요하지 않습니다. 라우트 파일에서 해당 파일을 제거하고 서버를 다시 시작하여 변경 사항이 있는지 확인할 수 있습니다. – Firyn
외부 경로가 실제 문제를 모호하게 만들었습니다.'views/pages /'디렉토리가 존재하지 않았습니다! (나는 그것을 서버에 올려 놓기 위해 저장 필터를 사용하고 있었고, 전에 이것을 알아 차리지 못했다. 나는 바보가된다.) – acobster