I'm getting Ruby on Rails set up on a fresh installation of Snow Leopard. After battling (and beating) MySQL and Sphinx problems, I'm stuck on a stupid error related to HAML.
Essentially I'm getting a missing template error for every view that uses HAML. I can add a blank xxx.html.erb file and and a (blank) page loads fine. But xxx.html.haml throws the error, even though that file definitely exists in the appropriate directory.
Here is the error from the development server:
ActionView::MissingTemplate (Missing template sections/index.erb in view path app/views):
haml (2.2.4) rails/./lib/sass/plugin/rails.rb:19:in `process'
I am using the haml gem (2.2.4), rails gem (2.3.4), and ruby 1.8.7. I did run haml --rails . from my RoR app root directory; the init file is in the vendor/plugins/haml directory. I have confirmed that "require 'haml'" => true via IRB.
Any help would be appreciated!
In response to Yaraher:
Tried un- and re-installing, which raised no errors except with the rdocs ("Could not find main page README.rdoc").
In script/console:
>> require 'haml'
=> []
Update:
Installing an old version of Rails known to work with HAML in this project seems to have "fixed" the problem. I'd still be curious to hear a real answer to this problem -- I don't want to be stuck at 2.3.2.
sudo gem install -v 2.3.2 rails
Update 2:
This is definitely caused by a difference between Rails 2.3.2 and 2.3.4. With both gems installed I can set which is used in my environment.rb file. HAML works fine with 2.3.2 and breaks as described with 2.3.4.
Time for the embarrassing answer to this question:
There is a difference between Rails 2.3.2 and 2.3.4 that does not recognize xxx.haml.html files as files that should be parsed by HAML (or ERB); this worked fine in 2.3.2. HAML files should always be named xxx.html.haml anwyay, so this isn't even a bug.
I didn't realize that this was the problem because I had the "hide file extensions" option turned on (on by default) in my fresh Snow Leopard installation. So when I tried switching the file extension through Finder to html.haml to test this, it actually changed it to haml.html.haml or some nonsense.
Moral of the story: I ran the following script and now HAML works with Rails 2.3.4.
path = '/path_to_rails_app/views/'
dir = Dir.new(path)
dir.each do |d|
if File.directory?(path+d)
Dir.new(path+d).each do |f|
if (f =~ /.*\.haml\.html$/) != nil
File.rename(path+d+'/'+f, path+d+'/'+f.gsub('haml.html', 'html.haml'))
end
end
end
end
Try to rename your template to
sections/_index.haml
or
sections/__index.haml
Related
I'm following Michael Hartl's Ruby on Rails tutorial, and I got stuck at trying to start rails server on my Windows 7 machine.
I'm trying to do this by following instructions in Chapter 1.2.5., i.e. by typing
rails server
However, instead of booting WEBrick, this returns the instructions for usage of 'rails' command. I've been googling this for a while, and some of the answers seem to have implied that something is wrong with the rails gem.
Now, I've found the rails gem folder ("C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\rails-3.2.3"), and it's empty!
Also when I try
rails -v
it returns "Rails 3.2.16", although I've removed this version of the gem; if I try
gem list
it kept telling me that the version is 3.2.3.
This persisted until I deleted railties version 3.2.16, which resulted in
rails -v
returning 'Rails 3.2.3', but I still can't boot WEBrick.
Any help would be appreciated.
Did you run the installer?
At the time of this writing, I recommend using the Ruby 2.0.0-p353.
http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353.exe?direct
Save yourself some future gem headaches and install the DevKit too.
http://rubyinstaller.org/downloads/
It should create a folder at C:\Ruby200. Start a new command prompt for the new paths to take affect.
Once Ruby is install, gem install Rails. From your other post, I recommend gem install rails -v 3.2.16
Then execute rails new project_name, then cd project_name. Then run rake db:migrate to create the initial database. At this point, you should be able to run rails server and visit localhost:3000 in your browser.
OK, I've managed to solve my problem.
I've seen a few more people having the same issue, but none of the solutions that I've found helped me, so here's what did it for me, though I'm not 100% sure what exactly was that one thing that actually did it...
I've followed the advice #scarver2 gave in response to my other question, and uninstalled both Rails and Railties gems from my crispy fresh installation of Ruby 1.9.3. (I've installed it using RailsInstaller). Then I've installed Rails 3.2.16 gem by typing
gem install rails -v 3.2.16
and this also installed the corresponding Railties 3.2.16 gem without my intervention.
Then I followed steps from chapters 1.2.3. and 1.2.5. of the tutorial, but making sure that line referencing ruby version in my Gemfile actually corresponds to the version of Ruby that I have installed.
I typed
ruby -v
in the console, to make sure that I have version 1.9.3. indeed. Confirming this, I've edited the Gemfile in my app so it says
ruby '1.9.3'
instead of ruby '2.0.0' line that's used in Listing 1.5. of the tutorial.
After that I've simply went to my app folder, and typed
bundle update
bundle install
in the console, and this time it did not return any errors as it did in my previous attempts. After that, typing
rails server
did what it should have, and my WEBrick server booted, allowing me to access my app on localhost. Yay!
Now, what I think may have gone wrong the last time was either me screwing up the Gemfile, so the gem versions and their dependencies got messed up. I also assume that ineptly trying to fix this by installing and uninstalling different versions of various gems did not quite help. What may have helped was uninstalling Rails and Railties gems, and installing Rails gem again.
I am facing issue when I am trying to work with rails 3.0.11. I initially worked with rails 3.2.6. Build a prototype application in Rails 3.2.6, Ruby 1.9.2 and gem 1.8.7. But then found, server on which we need to host is a shared server which can only support Rails 3.0.11, Ruby 1.8.7 and gem 1.7.2.
Hence I want to keep my dev environment exactly same before I ran into further issues. As I found there was some discrepancy in routes.rb of both the versions.
Steps I followed:
Uninstalled rails
Uninstalled ruby
Installed ruby from here.
This installed ruby version 1.8.7-p370 and gem 1.8.7
After this I installed rails by specifying version as 3.0.11
But still when I run command rails -v, it throws an error to me saying 'missing gem rails 3.2.6. Run bundle install to resolve the issue'
When I ran bundle install, it again completely installed rails 3.2.6 and problem remained unresolved.
Please suggest the clean way how shall I start my development on rails 3.0.11 without running into any issues?? Am I need to delete some registry or mapping in my system through which it is detecting rails 3.2.6 and creating issues??
Its urgent as I need to complete my dev by 7th September.
As I am new to stackexchange, please guide is it appropriate to ask question on the same related thread or shall I open new discussion for my problem?
#Gun - please note in response to one of your comments posted above - you DO need to change your Gemfile - if you are running rails -v from withing your project's directory, it will read the Gemfile.
There is a script located at script/rails - this is what runs when you run the rails command from the project directory. NOTE that this rails script requires your config/application.rb file - which in turn reads the Gemfile and bundles the referenced gems. Thus is your Gemfile still references 3.2.6, and it is not installed, rails -v will not work
Glad to hear the problem is fixed :)
As for the asset pipeline - if you are using rails 3.2.6 (or were using it) then you may have been using the asset pipeline to serve your assets (javascript files, CSS files, images, etc). If you were, and you downgrade to anything pre rails version 3.1, then anything being served through the asset pipeline will no longer work.
Here is a pretty good description of the asset pipeline: http://guides.rubyonrails.org/asset_pipeline.html
You should check also remove your Gemfile.lock or manually 'bundle update rails' when you change your rails dependency.
I suggest to use rbenv or rvm to create a virtual environment/sandbox where you can install your preferred ruby versions (e.g. 1.8.7) and keep tracking of your dependencies separately. This would save you a lot of effort.
Keep in mind that rails 3.0 has no asset pipeline support (it has been included in rails 3.1)! This is a very important difference and if you depend on it you will have big issues to solve for the downgrade.
Thanks a lot everyone for help.
I believe it was weird issue. I had heroku on the system. I was initially deploying my app on the same and then changed to another hosting server.
After uninstalling the heroku, it works perfectly fine. Probably, that was interfering somewhere. Although, not sure but problem is resolved.
Thanks a lot again for a great great help!!!
Meanwhile, I would request alup to throw some more light on asset pipeline support. Wots that? Could you please explain more??
Need to delete C:\Users\.ror folder and C:\Users\.gemfile and C:\Users\.gemfile.lock from your desktop..
Ive upgraded rails from 3.0.10 to 3.1.1 and now Im getting the following Error:
undefined method 'javascript_expansions' for ActionView::Helpers::AssetTagHelper:Module
but not on every page, just some pages are involved. I googled it already but I didnt find anything! Im running ruby 1.9.2 by the way...
Also my asset pipeline doesnt seem to work. Its not loading the application.cssand application.js file even its in the assets subfolders. Im getting a routing error each time I try to fetch any of the files.
I got the exact same error, after removing tinymce and running bundle install everything was running smooth, so heat up the coffee machine and try to remove suspect JavaScripts.
Maybe it was just a lucky shoot he he
I solved this problem adding the therubyracer gem to the Gemfile and runned bundle install. Thats it...
I am developing a rails 3 application and I am using Devise for authentication. Everything seems to be working just fine, but when I try to generate the views using rails generate devise:views, I get a bunch of errors like this:
/Library/Ruby/Gems/1.8/gems/bundler-1.0.2/lib/bundler/shared_helpers.rb:2:in `require': no such file to load -- rubygems (LoadError)
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.2/lib/bundler/shared_helpers.rb:2
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.2/lib/bundler/setup.rb:1:in `require'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.2/lib/bundler/setup.rb:1
My default template engine is HAMl and I have the hpricot gem installed (as it says to do on the Devise github page).
Any ideas?
Thanks
Give it a shot with bundle exec:
bundle exec rails g devise:views
It turns out that it had something to do with my gems being stored in a different location than ruby. I'm not sure why it suddenly became a problem with that particular command. But re-installing rubygems seemed to do the trick.
I'm a newbie to Ruby on Rails. My problem is, I am trying to upgrade the rails version from 1.2.3 to 2.3.4.
I changed the .rhtml files to .html.erb according to the rails version 2.3.4. I changed the environment and boot.rb settings according to the rails version, but when I try to run the application, I'am getting missing template error it is searching for the view with .rhtml extension but not for the html.erb. Please kindly help me with this.
Thank you
Did you change your RAILS_GEM_VERSION in the config/environment.rb file? It may still be looking for the 1.2.3 gem, as opposed to the 2.3.4 gem.
You can make sure whether you have upgraded properly or not by going to script/console and whether it prints out
Loading development environment (Rails 2.3.4)
or not as you enter the console, that might give you some hints.
Check if you have a copy of rails in the vendor directory. Also, what does script/about show?