开发者

Trying to call methods from gems in a view, getting "no such file" error

I have just installed a base installatio开发者_StackOverflown of rails and have edited the main page to view some basic html and a link to create a new blog post via ruby in the corresponding 'erb' file. I am trying to add some additional ruby commands on this same page via <%= %> tags.

<h1>Hello, Rails!</h1> <%= link_to "My Blog", posts_path %>

<p>
<%= require 'rubygems' %>
<%= require 'simplegeo' %>

<%= SimpleGeo::Client.set_credentials('token', 'secret') %>
<%= a = SimpleGeo::Client.get_context(coordinates,coordinates); a %>
</p>

When I load this page , I get the following error: no such file to load -- simplegeo

Can someone point me in the right direction? Many thanks!


In Rails 3, you need to add this gem to your "Gemfile" .. follow this: http://gembundler.com/rails3.html

Remove this completely.. Never do this in your views

<%= require 'rubygems' %>
<%= require 'simplegeo' %>

Once you restart your rails server, if you added "simplegeo" to your gemfile, it'll be auto-required.

Move this to your controller to start

SimpleGeo::Client.set_credentials('token', 'secret')
@simple_geo_client = SimpleGeo::Client.get_context(coordinates,coordinates)

Then in your view, you can access any variable that starts with @

To get started in Rails, check out http://railsforzombies.org/


In rails 3.x, you use Bundler to specify gems. No need to require, especially in views.

Correct way is:

Open Gemfile Set/List required gems inside using format:

source :rubygems
gem "simplegeo"
gem "some_other_gem"

Run bundle install (or just bundle) command in console.

now restart your server and gems are auto required.

Check out Rails guide on how to start.


Most probably you did not install Simplegeo gem properly, or did not attach it correctly in you IDE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜