gmaps4rails is not displaying the map - ruby-on-rails-3

I don't know what I am missing.
I saw in another post that gmaps4rails gem includes some javascripts code dealing with json, and in the code rendered of my page it doesn't appears.
The container window for the map is blank, without any map inside.
I am running rails 3.2.8, ruby 1.9.3 and gmaps4rails 1.5.5.
Thanks in advance.
Controller code
respond_to :json, :html
def mostrar_mapa_unidades
#json = Unidade.all.to_gmaps4rails
respond_with #json
end
View code
<%= gmaps4rails(#json) %>
<%= #json %>
Model code
acts_as_gmappable :process_geocoding => false
application.html.erb code
<!DOCTYPE html>
<html>
<head>
<title>SONep</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
<%= yield :scripts %>
</body>
</html>
Rendered web page code (main parts)
<link href="/assets/gmaps4rails.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.base.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.bing.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.mapquest.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.openlayers.js?body=1" type="text/javascript"></script>
<div class="map_container">
<div id="map" class="gmaps4rails_map"></div>
</div>
#json
[{"lat":"-23.701613","lng":"-46.547077"},{"lat":"-23.704757","lng":"-46.545274"},{"lat":"-23.7074712","lng":"-46.5419723"}]

Related

Rails - Yield a Partial in a Layout

I think this is a very simple problem and I could be just going about it incorrectly because I am new to rails, but here it goes......
What I want to do is render the results of my partial view in my application layout using a yield. I have a search bar at the top of my page that I want the results to display in the yield in the layout. Again, I'm not sure if this is the proper way to do this, so if it isn't, just let me know the best way.
Right now, I get a "Missing template events/search" error when I try and use the search on my page. If I add the following code to controller it gets all of the information properly, but doesn't render in the application layout, it just displays the partial:
render :partial => "events/search_results"
Here is what the relevant section controller looks like:
layout "application"
def search
#events = Event.search params[:search]
end
Here is the application layout (Please excuse the formatting, I tried to make it easily readable):
<!DOCTYPE html>
<html lang="en">
<head>
<title>XXXXXXX</title>
<!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"type="text/javascript"></script> <![endif]-->
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="navbar navbar-top">
<div class="navbar-inner">
<div class="container">
<%= render :partial => "events/search" %>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span1">
</br>
<div class="well well-small">
<center><h3>Filters</h3></center> </br>
<%= render :partial => "events/left_severity_filter" %>
<%= render :partial => "events/left_date_filter" %>
</div>
</div>
<div class="span8">
<%= yield %>
</div>
<div class="span3">
<%= render :partial => "events/right_filter" %
</div>
</div>
</div>
Any help would be much appreciated. Thanks.
You do not have the events/search.html.erb template in the views. Create this view template and it will be displayed where the yield is.

view not rendered properly in rails

I have a model - Products, ProductsController and a layout product. I declared the layout inside the controller. added the css/js/images to the app assets folder. I did everything the rails guide told me to do when I want to have a custom layout. But It still doesn't show the layout i declared but shows me the default page without any formatting and settings.
my files are as follows
Products Controller
class ProductsController < ApplicationController
layout "product"
# GET /products
# GET /products.json
def index
#products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #products }
end
end
end
and my layout file is
<!DOCTYPE html>
<html>
<head>
<title>Cool Amazon Products</title>
<%= stylesheet_link_tag "application" %>
<%= stylesheet_link_tag "bootstrap" %>
<%= stylesheet_link_tag "bootstrap-responsive" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">Cool Products from Amazon</a>
</div>
</div>
</div>
<%= yield %>
<%= javascript_include_tag "bootstrap" %>
</body>
</html>
the index.html.erb is the one that is generated by default!.
I am using twitter bootstrap for the UI. Please let me know if i'm missing something inorder to display the correct layout.
Ok, weird, that should work.
So, things to check:
Are you in development environment, or have you restarted your Rails app?
Are you using page or action caching, and you're not clearing them?
Could it be a caching issue on the web server?
That's about all that could be causing this.

WickedPDF missing layout

I have a controller like this:
def show
#professor = Professor.find(params[:id])
respond_to do |format|
format.html
format.pdf do
render :pdf => "file_name"
end
end
end
And a simple view like this:
<p>Professor: <%= #professor.first_name %></p>
<p>Email: <%= #professor.email if #professor.email %></p>
I also have a layout 'application.html.erb';
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Myapp" %></title>
<meta name="description" content="">
<meta name="author" content="">
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= yield(:head) %>
</head>
<body>
<header class="navbar navbar-fixed-top">
<nav class="navbar-inner">
<div class="container">
<%= render 'layouts/navigation' %>
</div>
</nav>
</header>
<div id="main" role="main">
<div class="container">
<div class="content">
<div class="row">
<div class="span12">
<%= render 'layouts/messages' %>
<%= yield %>
</div>
</div>
<footer>
</footer>
</div>
</div> <!--! end of .container -->
</div>
When I do the following command:
bundle exec wkhtmltopdf 'http://local.myapp.com:3000/professors/2' - > test.pdf
I get a pdf with all the styles and layout properly.
However, when I go to http://local.myapp.com:3000/professors/2.pdf I get an error saying:
Missing template professors/show with {:locale=>[:en], :formats=>[:pdf], :handlers=>[:erb, :builder, :coffee]}
So, then I changed my controller#show action to be like this:
def show
#professor = Professor.find(params[:id])
respond_to do |format|
format.html
format.pdf do
render :pdf => "file_name",
:template => 'professors/show.html.erb'
end
end
end
That helps me to render the view, but unfortunatelly it doesn't render the styles and the layout. My questions are:
Why do I need to specify the template?
Why is the layout not being rendered in the PDF?
You need to rename your view to show.pdf.html.erb or create a new show.pdf.erb.
The .pdf in the filename lets the handler know it can use it.
Also, you probably need to use the wicked_pdf_stylesheet_link_tag helper to get your styles to show up. If you want to have a dual-purpose view, then something like this may be necessary:
<% if params[:format] && params[:format] == 'pdf' %>
<%= wicked_pdf_stylesheet_link_tag 'application' %>
<% else %>
<%= stylesheet_link_tag 'application' %>
<% end %>

Does the gmaps4rails gem for Rails 3.1 allow use of a Google Maps API Key?

The documentation says that a provider key is not needed when using Google Maps. However, I want to use my Google API Key so that I can track my usage.
From the _scripts.html.erb file in the gem, it appears that there is no built-in support for using the provider_key with Google Maps. Is that right?
<% if enable_js == true && scripts.try(:to_sym) != :none %>
<% case map_options.try(:[], :provider) %>
<% when "openlayers" %>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<% when "mapquest" %>
<script src="http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js?key=<%= map_options.try(:[], :provider_key) %>"></script>
<% when "bing" %>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<% else %>
<script type="text/javascript" src="//maps.google.com/maps/api/js?v=3.5&sensor=false&libraries=geometry<%= gmaps4rails_js_libraries(map_options.try(:[], :libraries)) %>"></script>
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script>
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js"></script>
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
<% end %>
<% if Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR < 1 %>
<% unless scripts.try(:to_sym) == :api %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.base.js' %>
<% end %>
<% case map_options.try(:[], :provider) %>
<% when "openlayers" %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.openlayers.js' %>
<% when "mapquest" %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.mapquest.js' %>
<% when "bing" %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.bing.js' %>
<% else %>
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.googlemaps.js' %>
<% end %>
<% end %>
<% end %>
If yes, are there any plans to add support for a Google Maps provider key? Or am I better off just hacking it in myself? :-P
<script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3.5&sensor=false&libraries=geometry<%= gmaps4rails_js_libraries(map_options.try(:[], :libraries)) %>"></script>
<script type="text/javascript" src="https://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script>
<script type="text/javascript" src="https://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js"></script>
<script type="text/javascript" src="https://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
src modification is needed.

Webbrick won't include the correct .css file

I'm following one of the best tutorials/books I have ever come across, the Ruby On Rails Tutorial
but I am trying to include the "blueprint" stylesheets and assets/blueprint/screen.css returns this:
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Action Controller: Exception caught</title>
I have checked that the path to the file is correct:
C:\triton2\public\stylesheets\blueprint\screen.css
And this is the top of my application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<%= csrf_meta_tag %>
<%= stylesheet_link_tag 'blueprint/screen.css', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/print.css', :media => 'print' %>
</head>
Any idea what could be causing this? Better yet, how could I diagnose the proper solution on my own? Nothing on the google is of use save this which recommended a db:migrate (didn't help)
[edit]
The solution was to put the style sheet in C:\triton2\public\assets\stylesheets\blueprint\screen.css
and change application.html.erb to <%= stylesheet_link_tag 'stylesheets/blueprint/print.css', :media => 'print' %>
I might be wrong but I think it may need to be in the public/assets/stylesheets instead of just public/stylesheets if it is a rails 3.1 app.