Forum: Ruby on Rails undefined method `relative_url_root'

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Stephen F. (Guest)
on 2009-05-03 19:32
Hi all,

I've installed the ym4rgm plugin so that I can integrate a google map to
pinpoint locations of photos. I cant find where the error refers to.
I got the API key from google for http://localhost and put it into
config/gmaps_api_key (development and test).

The error is:
undefined method `relative_url_root' for ActionController::Base:Class
Extracted source (around line #2):
1: <% content_for :head do %>
2:   <%= GMap.header %>
3: <% end %>
4:




My photos_controller show method is:

 def show
    @photo = Photo.find_by_user_id_and_id(params[:user_id],
                                          params[:id],
                                          :include => :user)
    if @photo.show_geo && (@photo.geo_lat && @photo.geo_long)
      @map = GMap.new("map_div_id")
      @map.control_init(:map_type => false, :small_zoom => true)
      @map.center_zoom_init([@photo.geo_lat, @photo.geo_long], 8)

      marker = GMarker.new([@photo.geo_lat, @photo.geo_long],
                           :title => @photo.title,
                           :info_window => @photo.body)
      @map.overlay_init(marker)
    end
    respond_to do |format|
      format.html # show.rhtml
      format.xml  { render :xml => @photo.to_xml }
    end
  end

The code for displaying the embedded map (show) is:

<% content_for :head do %>
  <%= GMap.header %>
<% end %>

<%= image_tag @photo.public_filename, :id => 'photo' %>

<% if @map %>
  <div id="gmap">
    <%= link_to_function 'Hide Map',
          "Element.hide('gmap'); Element.show('showmaplink')" %>
    <%= @map.to_html %>
    <%= @map.div(:width => 650, :height => 200) %>
    <br />
  </div>
  <%= link_to_function 'Show Map',
        "Element.show('gmap'); Element.hide('showmaplink')",
        :id => 'showmaplink',
        :style => 'display:none' %>
<% end %>
Stephen F. (Guest)
on 2009-05-03 19:39
Sorry, I should have added the trace:

vendor/plugins/ym4r_gm/lib/gm_plugin/map.rb:36:in `header'
app/views/user_photos/show.rhtml:2:in
`_run_erb_47app47views47user_photos47show46rhtml'
app/views/user_photos/show.rhtml:1:in
`_run_erb_47app47views47user_photos47show46rhtml'
app/controllers/user_photos_controller.rb:38:in `show'
pharrington (Guest)
on 2009-05-04 02:01
(Received via mailing list)
The source the the error is the ym4rgm plugin:

a << "<script src=\"#{ActionController::Base.relative_url_root}/
javascripts/ym4r-gm.js\" type=\"text/javascript\"></script>\n" unless
options[:without_js]

However, it's strange that that error is happening, as
ActionController::Base.relative_url_root has been around for awhile.
What version of Rails are you running? You can also try changing that
line in ym4r_gm/lib/gm_plugin/map.rb to something like:

a << javascript_include_tag 'ym4r-gm' unless options[:without_js}

To see if that resolves the issue.

On May 3, 11:39 am, Stephen F. <removed_email_address@domain.invalid>
Stephen F. (Guest)
on 2009-05-04 11:05
pharrington wrote:
> The source the the error is the ym4rgm plugin:
>
> a << "<script src=\"#{ActionController::Base.relative_url_root}/
> javascripts/ym4r-gm.js\" type=\"text/javascript\"></script>\n" unless
> options[:without_js]
>
> However, it's strange that that error is happening, as
> ActionController::Base.relative_url_root has been around for awhile.
> What version of Rails are you running? You can also try changing that
> line in ym4r_gm/lib/gm_plugin/map.rb to something like:
>
> a << javascript_include_tag 'ym4r-gm' unless options[:without_js}
>
> To see if that resolves the issue.
>
> On May 3, 11:39�am, Stephen F. <removed_email_address@domain.invalid>

Hi,

I'm using 2.0.2. Im not 100% what you meant in your post. Do you mean
replace the whole line with the line a "<< javascript_include_tag
'ym4r-gm' unless options[:without_js}"? (This gives an 'unexpected
tSTRING_BEG' error). Apologies if this seems trivial, I am a novice to
rails :@/
Frederick C. (Guest)
on 2009-05-04 12:03
(Received via mailing list)
On May 4, 8:05 am, Stephen F. <removed_email_address@domain.invalid>
wrote:
>
> Hi,
>
> I'm using 2.0.2.

THat;s before relative_url_root was defined on ActionController::Base
(used to live on AbstractRequest or something like that). If you're
new to rails and don't have historical baggage you may find it easier
to pick a newer version of rails.

Fred
Stephen F. (Guest)
on 2009-05-04 14:27
Frederick C. wrote:
> On May 4, 8:05�am, Stephen F. <removed_email_address@domain.invalid>
> wrote:
>>
>> Hi,
>>
>> I'm using 2.0.2.
>
> THat;s before relative_url_root was defined on ActionController::Base
> (used to live on AbstractRequest or something like that). If you're
> new to rails and don't have historical baggage you may find it easier
> to pick a newer version of rails.
>
> Fred

Thanks Fred. I'll upgrade to current rails and see if how it goes

Stephen.
This topic is locked and can not be replied to.