Reputation: 453
I am new to rails and just created a new project. I created the following view in Haml, index.html.haml to be exact. However this is the source I get when I run the app. I get no html, or title tags that I also created in Haml. The first is the source, the second is the contents of my Haml file.
<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>
The index.html.haml file:
%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
This is the application.html.haml file that I created:
!!! 5
%html
%head
%title Rotten Potatoes!
= stylesheet_link_tag 'application'
= javascript_include_tag 'application'
= csrf_meta_tags
%body
= yield
Am I missing something here?
Here is the controller code:
class MoviesController < ActionController::Base
def index
@movies = Movie.all
end
def show
id = params[:id]
@movie = Movie.find_by_id(id)
end
end
Upvotes: 0
Views: 912
Reputation: 430
remove views/layouts/application.html.erb the erb is eclipsing the applcation.html.haml
Upvotes: 0
Reputation: 734
1.) The simplest solution is to rename your application.html.haml to movies.html.haml in app/views/layouts directory, because Rails first looks for a file in app/views/layouts with the same base name as the controller.
If there is no controller specific layout, Rails should use theoretically app/views/layouts/application.html.erb or app/views/layouts/application.html.haml. This doesn't work for me either in Rails 3.2.2.
2.) Other possibility is to define 'application' as layout for your controller:
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
Hope that helps.
Upvotes: 0
Reputation: 315
Change your movies controller to inherit from ApplicationController
instead of ActionController::Base
:
class MoviesController < ApplicationController
Hope that helps.
Upvotes: 3
Reputation: 2993
Delete %html
application.html.haml example:
!!! 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"
Upvotes: 1