Rails is suddenly trying to render ERB instead of Haml and I can't figure out why. I've created new rails projects, reinstalled Haml, and reinstalled Rails.
Here's exactly the steps I take when making my application (Rails 2.3.2):
rails> rails test
rails> cd test
rails\test> haml --rails .
rails\test> ruby script\generate model user email:string password:string
rails\test> ruby script\generate controller users index
rails\test> rake db:migrate
Here's what the UsersController looks like:
class UsersController < ApplicationController
def index
#users = User.all
end
end
My routes:
ActionController::Routing::Routes.draw do |map|
map.resources :users
end
I now create views\users\index.html.haml:
%table
%th(style="text-align: left;")
%h1 Users
- for user in #users
%tr
%td= user.email
%td= user.password
Annnd run the server...
I navigate to localhost:3000\users and I get this error message:
Template is missing
Missing template users/index.erb in view path app/views
For some reason Rails is trying to find and render .erb files instead of .haml files.
vendor\plugins\haml\init.rb exists, untouched.
I've reinstalled Haml (Pretty Penny) multiple times and still get the same results.
I've also tried adding config.gem 'haml' to my environment.rb but this also doesn't work.
I can't figure out why suddenly rails will not render haml for me.
Hi it seem like haml is not enabled as Rails plugin ,in order to enable it use the following command .
Go to your application folder from the command prompt type the following
$ cd ..
$ haml --rails <yourproject>
if this doesnot work try installing haml gem with the following code
$ gem install haml
I tried with above example , it did work for me ,i have haml gem installed in my ubuntu system .
Good luck !
NOTE: "haml --rails" was deprecated in HAML 3.1
It's worth noting that the fact that the error message says that it couldn't find index.erb doesn't mean that it didn't look for index.haml too. The erb extension is hard-coded into the error message.
I thought that I had the same problem you describe, but it turned out that my application simply couldn't find my partial at all - it had nothing to do with the file extension.
I had this same problem (see this post) with Rails 2.3.4. Multiple gem uninstall/gem install rails didn't fix the problem. But downgrading to Rails 2.3.2 worked! (I know HAML previously worked in this project with this version of Rails).
sudo gem install -v 2.3.2 rails
Using Rails 3.1, I ran in to the same error and had to restart the web server.
I have this old project in rails 2.3.18, where the gems are managed using bundler, and all I had to do was explicitly use version 3.1.3 It did not work with the latest version (4.0). So in my version I added
gem 'haml', '3.1.3'
did bundle install and restarted my development server :)
Hmmm strange, this might be related.
According to: http://www.ruby-forum.com/topic/101346 you should use resource_url helpers in controllers and resource_path helpers in views. Right?
BUT, if I do use a resource_url helper in a redirect_to call inside my controller, then I get:
Missing template htp://localhost:4000/categories/new.erb in view path app/views
If I use the resource_path helper instead, there aren't any problems at all.
Anyone knows what could be wrong?
Why is the resource_url helper trying to redirect to an .erb file?
This is the error from the server log:
ActionView::MissingTemplate (Missing template http://localhost:4000/categories/new.erb in view path app/views):
haml (2.2.2) lib/haml/helpers/action_view_mods.rb:13:in `render'
app/controllers/categories_controller.rb:15:in `create'
haml (2.2.2) rails/./lib/sass/plugin/rails.rb:19:in `process'
P.S. This is in Rails 2.3.3
maybe your file name is wrong, if you have a whitespace in the end of the index.html.haml_, rails will wrong...
I ran into the same problem and I had to restart my server after installing Haml before my rails app recognized the changes.
I was having this issue with Ruby 1.9x, Rails 2.3.5, and HAML 3.1. I believe part of the issue is that some of the deprecated calls in 1.8 were removed in 1.9.
IMHO, if you want to use HAML in Rails 2, you'd be better off downgrading to Ruby 1.8. (which is what I did to fix my problem). In Rails 2, you MUST have the gem.config "haml" in your config.
Even better, move forward to Rails 3 on Ruby 1.9!
I've had this same problem.
The solution is documented in https://github.com/haml/haml/issues/672
You need to add
config.after_initialize do
require 'haml'
Haml.init_rails(binding)
end
inside your config/environment.rb within the Rails::Initializer.run do |config| configuration block !!
Updated - Not actual anymore:
I name all of my haml file only .haml
To illustrate:
test.haml
# not
test.html.haml
Update 5 years later:
I recommend to name them "file.format.haml", because its much more clear which format is the outcome...
Related
I have installed haml gem in my rails app (v4.2.0 beta4)
but it doesn't seem to compile any output.
I have included gem in my gemfile and ran bundle install and made sure
that I changed my html.erb files to html.haml
This is one of the template and all I see is the heading "New recipe".
%h1 New recipe
= render 'form'
= link_to 'Back', recipes_path
And nothing gets displayed for form partial.
I've come across someone with similar issue and the solution to the issue was making controller inherit
applicationController rather than actionController.
I wonder if this is what I need to do to make it working.
I would have thought installing haml gem would have handled everything needed to get it working.
In your Gemfile, put
gem "haml-rails"
And then of course bundle install
This is the ONLY gem you need to integrate HAML into your Rails app, as it provides the wrappers needed to be able to use ruby logic in your haml views. Simply using haml alone is not sufficient as haml is framework independent.
Since you've added the HAML gem (gem 'haml', '~> 4.0.5'), ran bundle install and restarted your server (Have you restarted your server??) I believe you have installed the Gem correctly.
When you say in your template file you see "New recipe", it makes me think the issue is not with the haml gem but with partial file.
Just to confirm, your partial is saved within the same folder (app/views/recipes/) as:
_form.html.haml
You need to make sure you have the underscore in front of the file name for partials.
I ended up downgrading my project to 4.1.8 and Haml works just fine.
gem 'haml-rails' was not necessary.
gem 'haml' did the job just fine.
I'm trying to use the Rails site map_generator gem to generate site maps for a 8,000,00 page site. The gem can be found here: https://github.com/kjvarga/sitemap_generator
Here is my code in sitemap.rb:
require 'rubygems'
require 'sitemap_generator'
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://www.mysite.com"
SitemapGenerator::Sitemap.create do
add '/content.aspx?page=privacypolicy'
Product.find_each do |product|
add product_path(ppid), :lastmod => content.updated_at
end
end
However, when I run
>> ruby sitemap.rb
I get an error that says:
sitemap.rb:9:in `block in ': uninitialized constant
SitemapGenerator::Interpreter::Product (NameError)
However "Product" is the correct name of my model. Why is this happening?
I'm running Rails 3.1.2 and Ruby 1.9.
I'm the author of the gem. Better to open an issue on the GitHub page in future. SitemapGenerator does work in Rails 3 and Ruby 1.9.*. If you are running Rails, you don't need these lines:
require 'rubygems'
require 'sitemap_generator'
Also you generate your sitemaps by running Rake:
rake sitemap:refresh:no_ping
What is happening in your case is that because you're not running through Rake, the script does not know about the Product class, since your Rails environment hasn't been loaded.
Well, I wasn't able to get this gem working. My guess is that it doesn't work on Rails 3.1.2 or with Ruby 1.9. However, I was able to get another gem (big_sitemap) to work. Here is the link to it.
https://github.com/alexrabarts/big_sitemap
I've added the delayed_job gem to my gemfile and installed correctly but when I try to run the following line:
Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc
I get the error 'uninitialized constant Delayed::Job'
Can somebody explain what i need to do here? I've tried running 'rake jobs:work' beforehand but it also returns the 'uninitialized constant Delayed::Job' error. Additionally, I've added "require 'delayed_job'" to the file (application.rb) without much luck.
If you've upgraded to delayed_job version >=3 you'll need to add this (presuming you're using ActiveRecord):
# Gemfile
gem 'delayed_job_active_record'
Did you follow the installation instructions on the README file? https://github.com/collectiveidea/delayed_job
Add this to your gemfile:
gem 'delayed_job_active_record'
and then run this at the console:
$ rails generate delayed_job:active_record
$ rake db:migrate
You need to create the delayed jobs table in the database (this assumes you're using active record).
For Rails 3, all you need to do is include it in the gemfile, run that code above to create the table and migrate the database, then restart your server and go!
I'm using delayed job within an engine (so the gem is specified in a .gemspec rather than Gemfile) and was getting the same error. I found that I could solve the problem by using:
require 'delayed_job_active_record' # fixes problem
rather than
require 'delayed_job' # doesn't
Just in case, if this is still unanswered, check the below link
http://www.pipetodevnull.com/past/2010/4/14/uninitialized_constant_delayedjob/
edit: Alternative, just upgrade to the latest version - 2.1
i was struggling a while back with the same problem. i was following ryan bates screencast on delayed_job and got the same error 'uninitialized constant Delayed::Job'. In the screencast ryan creates a file called mailing_job.rb(located under lib folder) with the delayed_job perform method inside, which allows you to use the enqueue method. After doing some research i found that rails 3 does not automatically load the lib folder files into your app.(not entirely sure)
Try this
In your controller where you use this:
"Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc"
Try to require the file like this.
require 'mailing_job'
class AssetsController < ApplicationController
def some_method
Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc
end
end
Version change possibility : if you jump from the 2.1.x to the 3.x version of the gem via a non locked down bundle, you may have a similar issue.
I've been trying to use HTTParty in my rails code
sudo gem install httparty
From the command line I can now successfully do
httparty "http://twitter.com/statuses/public_timeline.json"
When I try this in my rails app
require 'rubygems'
require 'httparty'
class FooController < ApplicationController
include HTTParty
def bar
blah = HTTParty.get("http://twitter.com/statuses/public_timeline.json")
end
end
I get the error message "no such file to load -- httparty"
I suspect there is something wrong with my environment?
You don't need to do 'include HTTParty' inside the Controller. Just remove that and it should work. I just tested it and it worked for me. If this doesn't work for you, you should add the gem to your environment.
Usually if you use a gem inside your Rails application, you should add the following to environment.rb:
config.gem "httparty"
The gem will be available in the application now and you don't need to add 'require' inside the Controller. Also, you don't need to require RubyGems inside a Controller.
When you use Rails 3, you need to put the following inside the Gemfile:
gem "httparty"
I hope it works for you. :)
The problem is, if you load a new gem, you have to restart the server even if you are in development.
I had this same error. I tried moving the require HTTParty all over, but found, all I needed to do was restart the rails server In the end I did not need to 'require HTTParty' nor 'include' it. It just needed to be loaded into rails.
1)include the httpary in your gemfile
open your gem file then add
gem 'httparty','YOUR VERSION NUMBER'
2) run bundle install in your command prompt of the app file
3) restart the server
Ran into the same problem. Then I switched from Ruby 1.8.7 to Ruby 1.9.2 and all errors varnished into thin air.
(Yes, it first took me quite some hours to come up with the possibility that the Ruby version might be the problem. Configured a secundairy server to avoid possible conflicts with 2 ruby versions, and after way to many hours I got my RoR stack up and running. And the first test with httparty (based on the example on top) worked out of the box! Finally can sleep RESTfully again :-)
I run into the same error whilst reviewing a project from a student, I change the name of the Gem from uppercase to lowercase then run bundle install. I then went ahead to change the format in which they were being imported from
require 'HTTParty' to require 'httparty' and boom it worked
How to make it work?
I have a file index.html.haml
and a index.html.erb. the erb one works, then when i delete the erb, it gives me the template is missing error.
I have rails 2.3.4 and installed the haml gem.
"Template is missing
Missing template profiles/index.erb in view path app/views"
Add config.gem "haml" to your Rails::Initializer.run block in your envrionment.rb file. The old haml --rails yourproject is being phazed out.
You also need a run haml --rails yourproject which will install a initalizer in vender/plugins/haml.