google-maps-api-3 ruby on rails - google-maps-api-3

I am getting the following error
ReferenceError: Can't find variable: google
when I am rendering a page the first time which should display the google maps. The first part of the page is shown correctly, but at the bottom the entire div with the map is missing. After click on refresh the page is rendered correctly. This error is the same in dev and prod and shows up for page in the application containing a google map. Don't know how to fix it.
Here are more details about the error from the Safari's console:
TypeError: 'undefined' is not a constructor (evaluating 'new google.maps.OverlayView()')
TypeError: 'undefined' is not a constructor (evaluating 'new google.maps.OverlayView')
Below is the code of one of this pages generating the errors above.
<% provide(:title, 'Current TBMs Location and Statistics') %>
<% if signed_in? %>
<h3>TBMs location and statistics - Today's date: <%=#current_date%></h3>
<div>
<div class="pull-left">
<%= link_to "Daily Progress", progresstable_path, class: "btn btn-sm btn-primary" %>
<%= link_to "Daily Stats", tbms_stats_table_path, class: "btn btn-sm btn-primary" %>
</div>
<div class="pull-right">
<%= "Today's: " %>
<%= link_to "Schedule", schedules_path, class: "btn btn-sm btn-primary" %>
<%= link_to "Readings List", all_readings_path, class: "btn btn-sm btn-primary" %>
</div>
</div>
</br></br>
<div class="container">
<div class="pull-left">
<h5>
<%= "TBM ID: " %>
<%= #tbms_progress_W.tbm_id %>
<%= "aka TBM1 or 26900"%>
</h5>
<%= "Last Date: " %>
<%= #tbms_progress_W.daily_date %>
<%= "Max Station: " %>
<%= number_with_precision #tbm_w_location, precision: 2 %>
<%= "Status: " %>
<%= #tbms_progress_W.tbm_status %>
<%= "Since: " %>
<%= #tbm_w_days_since %>
</br>
<%= "Days total: " %>
<%= #tbm_w_days_since_commissioned %>
<%= "Days working: "%>
<%= #tbm_w_working_days %>
<%= "Days stopped: " %>
<%= #tbm_w_stopped_days %>
<%= "Located between: " %>
<% if #smp_w_after.present? %>
<%= #smp_w_after.smp_id %>
<% else %>
<%= "Unknown" %>
<% end %>
<%= " and: " %>
<% if #smp_w_before.present? %>
<%= #smp_w_before.smp_id %>
<% else %>
<%= "Unknown" %>
<% end %>
</br>
<%= "Total excavated: " %>
<% if #tbm_w_location.present? %>
<%= #tbm_w_location - #tbms_W_initial.max_station %> <%="m"%>
<% else %>
<%= "Unknown" %>
<% end %>
<%= "Excavation speed: " %>
<% if #tbm_w_location.present? %>
<%= number_with_precision (#tbm_w_location - #tbms_W_initial.max_station) / #tbm_w_working_days, precision: 2 %> <%="m/day"%>
<% else %>
<%= "Unknown" %>
<% end %>
<%= "Excavated since yesterday cut off time: " %>
<% if #tbm_w_location.present? %>
<%= #tbm_w_location - #tbms_progress_W2.max_station %> <%="m"%>
<% else %>
<%= "Unknown" %>
<% end %>
</br>
<%= "Average distance excavated in the previous 24 hours: " %>
<% if #tbm_w_location.present? %>
<%= #tbms_progress_W2.max_station - #tbms_progress_W1.max_station %> <%="m"%>
<% else %>
<%= "Unknown" %>
<% end %>
<% if #tbm_w_lat == nil or #tbm_w_lon == nil %>
</br>
<%= "TBM latitude and longitude cannot be calculated, missing near SMP northing and easting" %>
</br>
<%= "TBM approximate address: not available" %>
<% else %>
</br>
<%= "Latitude: " %>
<%= number_with_precision #tbm_w_lat, precision: 6 %>
<%= " Longitude: " %>
<%= number_with_precision #tbm_w_lon, precision: 6 %>
<%= "Address: " %>
<% if #tbm_w_result.empty? %>
<%= "Cannot calculate TBM W address, Geocoder unavailable" %>
<% else %>
<%= #tbm_w_result[0].address %>
<% end %>
<% end %>
<% if #current_date != #tbms_progress_W.daily_date %>
<h6 class="error-message">
<%= "Today's location for TBM W is not loaded" %>
<%= " Last TBM W recorded date was: " %>
<%=#tbms_progress_W.daily_date %>
</h6>
<% end %>
<h6> SMPs ahead of the current TBM W location: </h6>
<% if #tbm_w_location.present? and #smps_w_ahead.present? %>
<ol>
<li>
<%= "First line: " %>
<%= #smps_w_ahead[0].smp_id %> <%= #smps_w_ahead[0].final_inst_status %> <%= #smps_w_ahead[1].smp_id %> <%= #smps_w_ahead[1].final_inst_status %>
</li>
<li>
<%= "Second line: " %>
<%= #smps_w_ahead[2].smp_id %> <%= #smps_w_ahead[2].final_inst_status %> <%= #smps_w_ahead[3].smp_id %> <%= #smps_w_ahead[3].final_inst_status %>
</li>
<li>
<%= "Third line: " %>
<%= #smps_w_ahead[4].smp_id %> <%= #smps_w_ahead[4].final_inst_status %> <%= #smps_w_ahead[5].smp_id %> <%= #smps_w_ahead[5].final_inst_status %>
</li>
<li>
<%= "Fourth line: " %>
<%= #smps_w_ahead[6].smp_id %> <%= #smps_w_ahead[6].final_inst_status %> <%= #smps_w_ahead[7].smp_id %> <%= #smps_w_ahead[7].final_inst_status %>
</li>
</ol>
<% else %>
<%= "Unknown" %>
<% end %>
<h5>
<%= "TBM ID: " %>
<%= #tbms_progress_E.tbm_id %>
<%= "aka TBM2 or 27000"%>
</h5>
<%= "Last Date: " %>
<%= #tbms_progress_E.daily_date %>
<%= "Max Station: " %>
<%= number_with_precision #tbm_e_location, precision: 2 %>
<%= "Status: " %>
<%= #tbms_progress_E.tbm_status %>
<%= "Since: " %>
<%= #tbm_e_days_since %>
</br>
<%= "Days total: " %>
<%= #tbm_e_days_since_commissioned %>
<%= "Days working: "%>
<%= #tbm_e_working_days %>
<%= "Days stopped: " %>
<%= #tbm_e_stopped_days %>
<%= "Located between: " %>
<% if #smp_e_after.present? %>
<%= #smp_e_after.smp_id %>
<% else %>
<%= "Unknown" %>
<% end %>
<%= " and: " %>
<% if #smp_e_before.present? %>
<%= #smp_e_before.smp_id %>
<% else %>
<%= "Unknown" %>
<% end %>
</br>
<%= "Total excavated: " %>
<% if #tbm_e_location.present? %>
<%= #tbm_e_location - #tbms_E_initial.max_station %> <%="m"%>
<% else %>
<%= "Unknown" %>
<% end %>
<%= "Excavation speed: " %>
<% if #tbm_e_location.present? %>
<%= number_with_precision (#tbm_e_location - #tbms_E_initial.max_station) / #tbm_e_working_days, precision: 2 %> <%="m/day"%>
<% else %>
<%= "Unknown" %>
<% end %>
<%= "Excavated since yesterday cut off time: " %>
<% if #tbm_e_location.present? %>
<%= #tbm_e_location - #tbms_progress_E2.max_station %> <%="m"%>
<% else %>
<%= "Unknown" %>
<% end %>
</br>
<%= "Average distance excavated in the previous 24 hours: " %>
<% if #tbm_e_location.present? %>
<%= #tbms_progress_E2.max_station - #tbms_progress_E1.max_station %> <%="m"%>
<% else %>
<%= "Unknown" %>
<% end %>
<% if #tbm_e_lat == nil or #tbm_e_lon == nil %>
</br>
<%= "TBM latitude and longitude cannot be calculated, missing near SMP northing and easting" %>
</br>
<%= "TBM approximate address: not available" %>
<% else %>
</br>
<%= "Latitude: " %>
<%= number_with_precision #tbm_e_lat, precision: 6 %>
<%= " Longitude: " %>
<%= number_with_precision #tbm_e_lon, precision: 6 %>
<%= "Address: " %>
<% if #tbm_e_result.empty? %>
<%= "Cannot calculate TBM E address, Geocoder unavailable" %>
<% else %>
<%= #tbm_e_result[0].address %>
<% end %>
<% end %>
<% if #current_date != #tbms_progress_E.daily_date %>
<h6 class="error-message">
<%= "Today's location for TBM E is not loaded" %>
<%= " Last TBM E recorded date was: " %>
<%=#tbms_progress_E.daily_date %>
</h6>
<% end %>
<h6> SMPs ahead of the current TBM E location: </h6>
<% if #tbm_e_location.present? and #smps_e_ahead.present? %>
<ol>
<li>
<%= "First line: " %>
<%= #smps_e_ahead[0].smp_id %> <%= #smps_e_ahead[0].final_inst_status %> <%= #smps_e_ahead[1].smp_id %> <%= #smps_e_ahead[1].final_inst_status %>
</li>
<li>
<%= "Second line: " %>
<%= #smps_e_ahead[2].smp_id %> <%= #smps_e_ahead[2].final_inst_status %> <%= #smps_e_ahead[3].smp_id %> <%= #smps_e_ahead[3].final_inst_status %>
</li>
<li>
<%= "Third line: " %>
<%= #smps_e_ahead[4].smp_id %> <%= #smps_e_ahead[4].final_inst_status %> <%= #smps_e_ahead[5].smp_id %> <%= #smps_e_ahead[5].final_inst_status %>
</li>
<li>
<%= "Fourth line: " %>
<%= #smps_e_ahead[6].smp_id %> <%= #smps_e_ahead[6].final_inst_status %> <%= #smps_e_ahead[7].smp_id %> <%= #smps_e_ahead[7].final_inst_status %>
</li>
</ol>
<% else %>
<%= "Unknown" %>
<% end %>
</div>
</div>
<div style='width: 800px;'>
<div id="map" style='width: 920px; height: 500px;'></div>
</div>
<% else %>
<%= render 'instruments/unsigned' %>
<% end %>
<script src="//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js' type='text/javascript'></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js' type='text/javascript'></script>
<script type="text/javascript">
buildMap (<%=raw #hash.to_json %>);
</script>

Problem solved: put all links refs to css and js in application.html.erb, after turbolinks and good by errors. Seems that browsers need to cache all of this before page x in the app is due for render.

Related

My "Delete Comment" function from my Ruby on Rails Blog Website doesn't work and I don't know why

My "Delete Comment" function from my Ruby on Rails Blog Website doesn't work and I don't know why.
Here is my error:
Routing Error
No route matches [POST] "/posts/17/comments/9"
Rails.root: C:/Sites/blog
Routes
Routes match in priority from top to bottom
"comments_controller.rb" file:
class CommentsController < ApplicationController
def create
#post = Post.find(params[:post_id])
#comment = #post.comments.create(params[:comment].permit(:name, :body))
redirect_to post_path(#post)
end
def destroy
#post = Post.find(params[:post_id])
#comment = #post.comments.find(params[:id])
#comment.destroy
redirect_to post_path(#post)
end
end
"_comment.html.erb":
<div class="comment clearfix">
<div class="comment_content">
<p class="comment_name"><strong><%= comment.name %></strong></p>
<p class="comment_body"><%= comment.body %></p>
<p class="comment_time"><%= time_ago_in_words(comment.created_at) %> Ago</p>
</div>
<p>
<%= link_to 'Delete', [comment.post, comment],
method: :detele,
class: "button",
data: {confirm: 'Are you sure?'}
%>
</p>
</div>
"_form.html.erb":
<%= form_for([#post, #post.comments.build]) do |f| %>
<%= f.label :name %><br>
<%= f.text_field :name %><br>
<br>
<%= f.label :body %><br>
<%= f.text_area :body %><br>
<br>
<%= f.submit %>
<% end %>
"show.html.erb":
<div id="post_content">
<h1 class="title">
<%= #post.title %>
</h1>
<p class="date">
Submitted <%= time_ago_in_words(#post.created_at) %> Ago
| <%= link_to 'Edit', edit_post_path(#post) %>
| <%= link_to 'Delete', post_path(#post),
method: :delete,
data: { confirm: 'Are you sure?' } %>
</p>
<p class="body">
<%= #post.body %>
</p>
<div id="comment">
<h2><%= #post.comments.count %> Comments </h2>
<%= render #post.comments %>
<h3>Add a comment: </h3>
<%= render "comments/form" %>
</div>
</div>
"posts.rb":
class Post < ApplicationRecord
has_many :comments, dependent: :destroy
validates :title, presence: true
validates :body, presence: true
end
"routes.rb":
Rails.application.routes.draw do
resources :posts do
resources :comments
end
root "posts#index"
end
I really don't know how to fix this. Please help me. Thank you! <3

Rails: Can't add CSS class from variable in link_to

SyntaxError occurs when:
<% #list1.each do |list| %>
<div class="well well-sm">
<%= list.test_name %> <%= link_to 'Do It', '#', class: <%= list.test_type %>
</div>
<% end %>
Tried also
class: <%= #{list}.test_type %>
and so on... what's wrong with it?
You have excess erb open tag <%=, instead:
<%= list.test_name %> <%= link_to 'Do It', '#', class: <%= list.test_type %>
^^^open close^^ ^^open ^^^open close^^
use:
<%= list.test_name %> <%= link_to 'Do It', '#', class: list.test_type %>
I suggest you read An Introduction to ERB Templating
try this:
<%= link_to 'Do It', '#', class: list.test_type %>
or
<%= link_to 'Do It', '#', class: "#{list.test_type}" %>

Changing font style of rails "notices" =>

I have the following notice when a user logs out of my website.
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Logged out!"
end
Only slight little bugbear, the "Logged out!" notice is in a sans font style, rather than a font style more in keeping with my website (i.e., font-family: sans-serif).
How do I go about changing this...?
Perhaps:
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => <div class="some_class">"Logged out!</div>
end
Where we can then edit the .some_class class within css...
Here is the application.html.crb code:
<!DOCTYPE html>
<html>
<head>
<title>Welcome!</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<!--<div id="user_nav">
<% if current_user %>
Logged in as <%= current_user.email %>.
<%= link_to "Log Out", log_out_path %>
<% else %>
<%= link_to "Sign Up", sign_up_path %> or
<%= link_to "Log In", log_in_path %>
<% end %>
</div>-->
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
<%= yield %>
</body>
</html>
Within application.html.crb, edit the following:
<div class="flash">
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>
</div>
Where there you go, you need to add the class there
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, :id => "flash_#{name}", class: 'flash' %>
<% end %>

Rails & Bootstrap Make button inline with text field

I'm working on a front end of web app. I would like to know how to make the button and textfield in line. Another question is how to make the error message displayed just below the textfield?
Picture:
https://www.dropbox.com/s/vsdy3730flraes3/Screen%20Shot%202013-12-01%20at%204.47.20%20PM.png
Here is the code:
<div class="input-group" align="center" >
<%= form_tag(location_search_path,method: "get" ) do %>
<%= text_field_tag('location', params[:location], :size => 150, :placeholder=> "Enter city or zip code") %>
<%= button_tag(type: "submit", class: "btn btn-success ") do %>
Search
<i class="icon-search"></i>
<% end %>
<% end %>
</div>
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div data-alert="alert" class="alert-message <%= flash_class(level) %> fade in" align="center">
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
Add the <div class="form-inline"> to your form element to get the button and field onto the same line, and I guess you could us a <p> to make the message appear below it, though I would probably set up the input group in a row with columns to center it rather than the align tag you are using, and then put the messages into a new <row> below it in the same column.
<div class="input-group" align="center" >
<div class="form-inline">
<%= form_tag(location_search_path,method: "get" ) do %>
<%= text_field_tag('location', params[:location], :size => 150, :placeholder=> "Enter city or zip code") %>
<%= button_tag(type: "submit", class: "btn btn-success ") do %>
Search
<i class="icon-search"></i>
<% end %>
<% end %>
</div>
</div>
<p>
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div data-alert="alert" class="alert-message <%= flash_class(level) %> fade in" align="center">
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
bootstrap 3 has input groups... which are nice. http://getbootstrap.com/components/#input-groups
Try this in your code...
<%= form_tag location_search_path, method: 'get' do %>
<%= text_field_tag :location, params[:location], size: 150, placeholder: "Enter city or zip code" %>
<span class='input-group-btn'>
<%= submit_tag 'Search', class: 'btn btn-success' %>
</span>
<% end %>

Display fields within control when not null

I have the following code:
<% control StaffMembers %>
<li>
Name: <h2>$Name</h2>
</li>
<% end_control %>
I would like to ask how I would be possible to show the Name text field only if it is not null or empty.
An if statement within the control didn't work:
<% control StaffMembers %>
<% if $Name %>
<li>
Name: <h2>$Name</h2>
</li>
<% end_if %>
<% end_control %>
Thank you
Your code looks correct. Calling an if statement inside the control should work.
I would also recommend putting an if statement around your control to check if there are any StaffMembers before looping through them:
<% if $StaffMembers %>
<ul>
<% control $StaffMembers %>
<% if $Name %>
<li>
Name: <h2>$Name</h2>
</li>
<% end_if %>
<% end_control %>
</ul>
<% end_if %>
Or in Silverstripe 3 using loop instead of control:
<% if $StaffMembers %>
<ul>
<% loop $StaffMembers %>
<% if $Name %>
<li>
Name: <h2>$Name</h2>
</li>
<% end_if %>
<% end_loop %>
</ul>
<% end_if %>

Resources