Ruby on Rails view - ruby-on-rails-3.1

I am new in ruby on rails. I was trying to check some code. I copied all folders of an existing project from my friends and pasted them to a newly created project at my machine. And also changed the config file. It shows following error:
*Template is missing
Missing template movies/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "../Software Engineering for Software as a Service/Software/Project/rottenpotatoes/app/views"*
Some one suggested me that it is because haml is not installed, i installed haml by "gem install haml" but it still shows the same message. Can any one help me?

If rails had access to the HAML gem it would show HAML as a handler in that error. Your error does not. It's possible you need to restart your rails server.
You should be using the Gemfile for managing gems, though. Add gem 'haml' to your Gemfile. Go to your console and cd to the application directory. Run bundler to install the gems with the bundle command. Restart your rails server.

Related

Ruby script cannot load a gem installed via bundler

I am trying to include the ruby-mysql gem in my ruby script. I have installed the gem using bundler but when I run bundle exec ./mysql_connector, I receive the error ./mysql_connector:4:in ``require': cannot load such file -- ruby-mysql (LoadError). Can you please help me troubleshoot what the problem is?
What I did
Installed rails in my home directory.
I do not have root access to the server so I have installed rails in my local directory by following the instructions here:
http://www.r-bloggers.com/installing-ruby-on-linux-as-a-user-other-than-root/
Created a directory for my application.
My application resides in my home directory in a folder called connector. It has a Gemfile that looks like this:
source 'https://rubygems.org'
gem 'ruby-mysql'
Call bundle install.
Using ruby-mysql 2.9.14
Using bundler 1.11.2
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Bundled gems are installed into ./vendor/bundle.
Add dependencies to my script. My script is in connector/mysql_connector and it reads:
#!/home/dcox/bin/ruby
require 'rubygems'
require 'bundler/setup'
require 'ruby-mysql'
Make script executable. I saw that you need to run bundle exec using an executable file, so I followed the instructions here to make my script executable: http://commandercoriander.net/blog/2013/02/16/making-a-ruby-script-executable/
Run the script. I execute using bundle exec mysql_connector and see:
/home/dcox/bin/mysql_connector:4:in `require': cannot load such file -- ruby-mysql (LoadError)
from /home/dcox/bin/mysql_connector:4:in `<main>'
Is it the $LOAD_PATH? After searching around for answers, I discovered a lot of SO answers as well as a blog post (https://codedecoder.wordpress.com/2013/09/23/require-and-load-in-ruby-loaderror-cannot-load-such-file/) that seem to suggest the problem is that the gem is not installed in a directory on the $LOAD_PATH. Here is what I see when I run $LOAD_PATH from IRB:
irb(main):002:0> $LOAD_PATH
=> ["/home/dcox/lib/ruby/site_ruby/2.1.0",
"/home/dcox/lib/ruby/site_ruby/2.1.0/x86_64-linux",
"/home/dcox/lib/ruby/site_ruby", "/home/dcox/lib/ruby/vendor_ruby/2.1.0",
"/home/dcox/lib/ruby/vendor_ruby/2.1.0/x86_64-linux",
"/home/dcox/lib/ruby/vendor_ruby", "/home/dcox/lib/ruby/2.1.0",
"/home/dcox/lib/ruby/2.1.0/x86_64-linux"]
Next I checked to see the location of ruby-mysql:
dcox#analytics1:~/connector$ bundle show ruby-mysql
/data/home/dcox/connector/vendor/bundle/ruby/2.1.0/gems/ruby-mysql-2.9.14
Obviously my connector/vendor/bundle path is not on the $LOAD_PATH. I could add it, but I have a feeling I am missing something simple here because bundler is supposed to work as long as you follow the instructions, right?
Any advice or help is very much appreciated! Thanks!!
If you just want to require this specific gem, require 'mysql' should work (e.g., https://github.com/tmtm/ruby-mysql/blob/master/test/test_mysql.rb#L10).
Your file should call Bundler.setup http://bundler.io/bundler_setup.html
Better yet, if you instead call Bundler.require(:default) it will setup and require all the gems in your Gemfile for you.

Bundler using binstub generated for a different gem using Middleman

I am using Middleman to build a project. I receive this message any time I run a Middleman command:
Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub middleman-core` to work around a system/bundle conflict.
When I run bundle binstub middleman-core, I get this:
middleman-core has no executables, but you may want one from a gem it depends on.
bundler has: bundle, bundler
rack has: rackup
tilt has: tilt
erubis has: erubis
listen has: listen
sass has: sass, sass-convert, scss
Don't really know where to go and what to do from that message.
It is not causing the anything to fail and the server runs, but I feel like this could be a bigger issue if I leave it unfixed. This ended up happening when I was playing with s3_sync to push this up to s3 bucket and I gem installed middleman-sync_s3.
I have tried research and others led me through the path of deleting the bin/* file multiple times. I've tried updating the bin also and neither helps.
Any help is appreciated.
So I was hopping around the Gemfile trying to figure out what was going on. I had built a few previous projects in middleman and decided to look them up. I saw that I was using a previous version of Middleman 3.1.0 where as with this current project I was using Middleman 4.0.0
I reverted back to 3.1.0 and ran a bundle update. Tried running a Middleman command and the binstubs message no longer appears.
Ultimately, I think it had something with the way bundler plays with middleman-core.
gem install middleman-cli seems to help in case someone else is looking for a solution to this.

How do I list required gems for my system, so they are installed automatically when deploying it?

I am new to Ruby but I really enjoyed it.
I used Aptana Studio 3 as an IDE, but I feel it lacks support (even though I installed the undle). When I created a Ruby project, there were no files inside it.
I added a test.rb file and started playing with it.
Now I hav a simple project in which I needed to install some gems. To do so I opened the CMD, navigated to my project's folder and issued the command "gem install xxxx". On my test.rb I include the gems using require 'xxxx'.
What is the best practice to add gems?
If I ever wanted to deploy this application, I would need to add the gems to my production server. Is there any way I can list the required gems so that the server intalls it automatically when I run deploy the application?
thanks!
Put them in a Gemfile, it is used to manage the gem required by an application.
http://bundler.io/v1.3/gemfile.html
It might depend on where you are deploying to but I like to use Capistrano for deployment. Capistrano will install the gems for you by running bundler which reads your Gemfile.
Also checkout bundler. It will read your Gemfile (create one if you don't have one). To install your gems it is as simple as:
$ bundle install

How to install and use Slim template engine with Middleman

I'm new to Middleman and ruby in general.
I've installed Ruby
I've installed Middleman and the gems to get it running.
I need to use slim instead of the default template system.
So I installed the Slim gem. Slim's website only says that I need to require 'slim' in order to get it to work.
The middleman website says I only need add the template engine to the config.rb file, but it gives no examples...
For someone with no ruby background, this is no help.
I looked for several config.rb on git and they all have:
require 'slim'
And
# Set slim-lang output style
Slim::Engine.set_default_options :pretty => true
# Set template languages
set :slim, :layout_engine => :slim
I added that to my config.rb file and created the layout.slim and the index.html.slim
When I refresh my local server I get:
Not Found
`/' not found.
I have middleman installed with Boilerplace. I'm not sure if there are more files that I need to change, but I can't find any good resources online, which is odd.
Could anyone give me some direction as to what I'm missing?
So here we go... after much reading and searching google for examples I think I figured it out.
To get Slim working with Middleman
Add gem "slim" to your project's gemfile
go to command line, in your project folder and gem install bundler
In the config.rb file add require 'slim'
Start the middleman server to test it
The middleman-slim project by yterajima is helpful in this regard.
Install is very easy.
$ gem install middleman
$ gem install middleman-slim
$ middleman init PROJECT_NAME --template slim
Bundler tip: you can also include multiple gems at once using Bundler.require. If you have gems in groups, you can include them as such: Bundler.require :group1, :group2 ...

Ruby on rails application fails to run on one machine but runs on another (same setup)

I have problem with moving Ruby on Rails app between two machines,
Both of them have exactly the same OS and setup (Arch linux x86_64 updated today),
(well, this can not be true, because this problem happens, but I'm unable to spot any differences at the moment)
both have rails in version 3.2.12 and ruby 1.9.3
On my laptop everything works fine, app runs correctly,
on desktop command
rake assets:precompile
fails with error:
/usr/bin/ruby /usr/bin/rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets
rake aborted!
couldn't find file 'jquery'
(...)
I have this in my application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
and gem 'jquery-rails' in my Gemfile (bundle install completes successfully)
but this is probably irrelevant - rake fails in exactly same wqay without this gem installed.
I tried running rails server, webpage shows error:
cannot load such file -- sass
(in [path])
Problem must lay somewhere in my ruby/rails installation on desktop, app source is kept in git, both machines have the same revision with clean working dir - tmp is in .gitignore.
Asset pipeline is enabled in config/application.rb
I tried the following:
Deleted tmp directory
Reinstalled rails, jquery and couple of other gems
Used other environments (rake fails in all of them)
Downloaded jquery and put it in assets dir (this is supposed to be automatic in rails),
i this case rake assets:precompile fails on sass stylesheet compilation (I have sass-rails installed!)
I must be missing something obvious here, anyone had this problem before?
Do I need to purge my ruby installation or is there a simpler way to solve this?
(ps. Sorry about my poor English)

Resources