2012-03-06 2 views
0

저는 레일을 처음 사용하고 새로운 프로젝트를 만들었습니다. Haml, index.html.haml에서 다음 뷰를 생성했습니다. 그러나 이것은 내가 앱을 실행할 때 얻는 소스입니다. Haml에서 만든 HTML이나 제목 태그도 없습니다. 첫 번째는 소스이고, 두 번째는 내 Haml 파일의 내용입니다.레일 앱에 html 태그가 없습니다

<h2>'All Posts'</h2> 
<table id='posts'> 
    <thead> 
    <tr> 
     <th>Post Title</th> 
     <th>Post Entry</th> 
    </tr> 
    </thead> 

    <tbody></tbody> 
    <tr> 
    <td>First Post</td> 
    <td>Oylesine bir seyler</td> 
    </tr> 
</table> 

index.html.haml 파일 :

!!! 5 
%html 
    %head 
    %title Rotten Potatoes! 
    = stylesheet_link_tag 'application' 
    = javascript_include_tag 'application' 
    = csrf_meta_tags 

    %body 
    = yield 

내가 여기서 뭔가를 놓치고 있습니까 :

%h2 'All Posts' 

%table#posts 
    %thead 
    %tr 
     %th Post Title 
     %th Post Entry 

    %tbody 
    - @posts.each do |post| 
    %tr 
     %td= post.title 
     %td= post.body 

이 내가 만든 application.html.haml 파일이?

class MoviesController < ActionController::Base 
    def index 
    @movies = Movie.all 
    end 

    def show 
    id = params[:id] 
    @movie = Movie.find_by_id(id) 
    end 
end 
+0

후 관련 컨트롤러 코드를하시기 바랍니다 가리는되는 뷰/레이아웃/application.html.erb 를 제거합니다. –

+0

컨트롤러 코드를 추가했습니다 – eytanfb

+1

레이아웃을 선택하지 않았습니다. 'application.html.haml' 파일은 어디에 있습니까? 그것은'app/views/layouts/application.html.haml'에 있어야합니다. – matt

답변

2

이 영화 컨트롤러를 변경 여기

컨트롤러 코드에서 상속대신 ActionController::Base : 도움이

class MoviesController < ApplicationController 

희망.

1

삭제 %의 HTML

thisthis

application.html.haml 예 : 참조 :

!!! 5 
-# http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither 
-ie_html :class => 'no-js oldie', :lang => 'en' do 
    %head 
    -# To render a different stylesheet partial inside the head (i.e. for admin layout) 
    -# just copy _stylesheets.html.haml, and point to that partial instead. 
    = render "layouts/head", :stylesheet_partial => "layouts/stylesheets" 

    %body{ :class => "#{controller.controller_name}" } 
    #container 
     %header#header 
     = render "layouts/header" 

     #main{ :role => 'main' } 
     = render "layouts/flashes" 
     = yield 

     %footer#footer 
     = render "layouts/footer" 

    -# Javascript at the bottom for fast page loading 
    = render "layouts/javascripts" 
+0

가 작동하지 않았습니다. % html bu을 삭제했으며 소스에 html 태그가 없습니다. 내 스타일 시트가 웹 사이트에 적용되지 않는 이유는 무엇입니까? – eytanfb

+0

github에서 파일을 보았지만 HTML 태그를 제거하는 특정 내용을 볼 수 없었습니다. 뭔가 붙여 넣기 코드에서 찾아야 할 구체적인 것이 있습니까 – eytanfb

+0

응용 프로그램이 레이아웃을 사용하지 않는 것으로 보입니다. – dotoree

0

1.) 가장 간단한 해결책은 app/views/layouts 디렉토리에서 application.html.haml의 이름을 movies.html.haml로 바꾸는 것입니다. 이는 Rails가 먼저 동일한베이스를 가진 app/views/layouts에서 파일을 찾기 때문에 이름을 컨트롤러로 사용하십시오. 더 컨트롤러 특정 레이아웃이없는 경우

, 레일은 이론적으로 응용 프로그램/뷰/레이아웃/application.html.erb 또는 앱/뷰/레이아웃/application.html.haml를 사용해야합니다. 이것은 레일즈 3.2.2에서 나에게 도움이되지 않는다. 도움이

class MoviesController < ActionController::Base 
layout "application" 

    def index 
    @movies = Movie.all 
    end 

    def show 
    id = params[:id] 
    @movie = Movie.find_by_id(id) 
    end 
end 

희망 :

2) 다른 가능성은 컨트롤러에 대한 레이아웃으로 '응용 프로그램'을 정의하는 것입니다.

0

하면 ERB 너무 applcation.html.haml