I am new to Ruby on Rails and am trying to use the gmaps4rails gem. The longitude and latitude show up automatically but the map is not appearing. If I look at the page source info it seems like the map is being called and created so I'm not sure why it's not showing up.
This can be seen here:
<script src="//maps.google.com/maps/api/js?v=3.8&sensor=false&client=& amp;key=& amp;libraries=geometry&language=&hl=®ion=" 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 type="text/javascript">
Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
Gmaps.map.map_options.auto_adjust = true;
Gmaps.map.initialize();
Gmaps.map.markers = [{"lat":40.8217303,"lng":-73.9551369}, {"lat":41.4925374,"lng":-99.9018131},{"lat":50.3429668,"lng":18.5540869}];
Gmaps.map.markers_conf.do_clustering = true;
Gmaps.map.create_markers();
Gmaps.map.adjustMapToBounds();
Gmaps.map.callback();
};
Do I need to include some other files in my document to show the map? And where would those documents be? I am using Ruby 1.9.3 and Rails 3.2.12.
I see this type of question has been asked and answered many times, but I haven't been able to get a solution from those answers. Thanks for any help.
UPDATE:
Here is my view:
<br />
<%= link_to 'New Bathroom', new_bathroom_path %>
<%= gmaps4rails(#json) %>
Model:
acts_as_gmappable
def gmaps4rails_address
address
Controller:
def index
#bathrooms = Bathroom.all
#json = Bathroom.all.to_gmaps4rails
respond_to do |format|
format.html # index.html.erb
format.json { render :json => #bathrooms }
end
end
and application.html
<%= yield %>
<%= yield :scripts %>
<%= stylesheet_link_tag 'gmaps4rails' %>
</body>
</html>
One thing I'm wondering is if I need to copy some assets to the app. It says on the github site.
"""""""""""""""""""""""""""""""""""""""""
gmaps4rails.css will be copied to your app after you run the Rails generator. Be sure to require this file in your view for your first steps.
For Rails 3.0.x or without assets pipeline:
<%= stylesheet_link_tag 'gmaps4rails' %>
"""""""""""""""""""""""""""""""""""""""""""
Since I don't see the gmaps4rails.css file I wonder if that's the problem. Thanks for helping.
Post Debugger Details:
Yeah that's true. I have almost no experience with this stuff. I got Firebug as you recommended and discovered that when I glide over the page the google scripts in the debugger never get highlighted. I see that it did try to make a call to googleapis.com But the time for the different actions are zero, except for blocking and waiting. This makes me think nothing was sent from the google server. Under Get gmaps4rails.css it looks in my app/asset folder and has a 404 error. I'm learning how to understand all this info, and if I'm correct it seems like the server request to google was blocked for some reason and it thinks my css file is in the asset folder. If I am correct I really have no idea where to go from here. Please tell me what info would help make this problem clearer.
You need to run 'rails generate gmaps4rails:install'. That will supply the missing bits (and the css will be sourced automatically in rails 3.2).
After that, you should be good to go (based on the original question, and barring any subsequent changes).
I've been starting to use simple_form in my rails application, which is quite nice. But I was not able to find a function which allows me to rename a field, without the use of i18n.
I have a radio button in my formular, which allows to choose the delivery type. Controlled by that a few fields need a different naming (but its still the same field with the same information).
(e.g. there's a delivery note which is called weight note or notification depending on the delivery type, but contains the same information).
I checked the readme, the railscast and searched a lot but didn't find a build-in way to do that. One option of course would be to create a special locales file just for that, but that feels a little over the top.
I found my answer in a different question regarding simple_form. After looking for that part in the readme, I also found it there.
<%= simple_form_for #user do |f| %>
<%= f.input :username, :label => 'Whatever name you want..' %>
<% end %>
This also overwrites the name given in the i18n file.
<%= link_to "Delete Party", party_path(#party.id), :method => :delete %>
a GET is always called according to the logs. I just get redirected to the same show page when I click the delete link.
Instead of #party.id, use #party in party_path().
The solution worked for me..
I was using jQuery 1.4.4 and facing issues with the delete link, I read somewhere about the jQuery version issue and switched to jQuery 1.4.2 and delete link worked fine for me.
Hey,
I'm pretty new to rails and for learning effect, I try to implement my own authorization system.
Right now I'm having a Page Controller to control some static pages and nothing more, and a Session Controller where I plan to implement most of the authorization process.
My problem is, I have no clue how to get my partial to use the sessions-controller, when I add it to one of the static pages controlled by the pages controller.
It stated out with this http://ruby.railstutorial.org/chapters/sign-in-sign-out#top but i don't want it on an extra page.
so I tried setting the routes and I got an exception "no path found for '/'" as soon as I deleted "resources :sessions" it worked fine again.
my partial looks like this:
<%= form_for(User.new) do |f| %>
<%= f.submit "Login" %>
<% end %>
there's also a div class="action" block around the submit but can't find out how to escape it
this is included into my home via
<%= render 'sessions/new' %>
Thanks for your help
edit my solution:
I added to routes.rb:
resources :sessions
Furthermore I changed form_for(#user) to
<%= form_for(:session, url => sessions_path)
so this works.
I Highly recommed that you look at the railscast http://railscasts.com/episodes/250-authentication-from-scratch , it will give you an idea how to create authentication without forgetting some important steps.
Then you can use the gem devise which is an excellent authentication gem.
Have you tried putting your functions and everything for authentication within a Session Helpers file? Then, in your Application Controller if you add "include SessionsHelper" this should give you access to all the helper functions from Session that you should need
I am going through the rails 3 tutorial at railstutorial.org. I have just created an extremely simple scaffold Users.
The scaffold-generated destroy link does not work in Internet Explorer. It redirects to the show action instead of deleting the user.
This problem only happens in IE9 and IE8 (the only IE versions I've tested so far) The problem DOES NOT happen in Firefox. Can anyone tell me why this is happening?
The view:
<%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %>
Generated HTML:
Destroy
The controller:
def destroy
#user = User.find(params[:id])
#user.destroy
respond_to do |format|
format.html { redirect_to(users_url) }
format.xml { head :ok }
end
end
In Rails 3.1 with the asset pipeline, all the javascript is in application.js. So, rather than :defaults, you need "application".
<%= javascript_include_tag "application" %>
Make sure you have <%= javascript_include_tag :defaults %>
JS is now unobtrusive in rails 3, so the include is required to make it work.
Replace public/javascripts/rails.js of your application with this one:
https://github.com/rails/prototype-ujs/raw/master/src/rails.js
This is updated recently (2010/11/13).
The rails.js bundled with Rails 3.0.0/3.0.1 does not work well on Internet Explorer.
You need to upgrade your prototype distribution to 1.7 instead of 1.7rc2 (which doesn't have full support for IE 9). The latest Rails gem (at time of writing( in the gem repo is bundling 1.7rc2. Go to the prototype homepage, download the new 1.7 release and replace this with the bundled prototype.js.
I couldn't get it to work with IE9 with the default javascript libraries, so I installed jquery-rails and it works just fine. Not perhaps the ideal solution, but if it works...
By default, new rails projects are created with Prototype javascript libraries, with some prototype-specific helper functions in "public/javascript/rails.js". The scaffolding relies on some of these helpers to handle some things, like destroying a record, since there isn't a good javascript-free way of making a DELETE request, etc.
Make sure that your pages are loading both the javascript libraries and the "rails.js" file, which are needed to make the scaffolding work (see theschmitzer's answer, or check in Firebug).
Second, if you are using jQuery, install the 'jquery-rails' gem and then run "rails g jquery:install". This will remove the Prototype libraries, install the jQuery libraries, and update the helpers to use jQuery.
Try replacing your javascript default include with:
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "jquery.min" %>
<%= javascript_include_tag "rails" %>
after following the steps above to get the latest jquery.js, jquery.min.js, and rails.js. That worked for me, anyway.
Or, replace the meaning of :defaults in application.rb:
config.action_view.javascript_expansions[:defaults] = %w(jquery jquery.min rails)
And then your application layout can still look have
<%= javascript_include_tag :defaults %>
This is probably because the loading of your script (rails.js and/or application.js) happens in head. At script execution time, there are no elements in your DOM with the attributes data-confirm and data-method.
So, the solution is to move the javascript tag to the end of <body>. At this time, the DOM has most likely been loaded and the javascript will find your elements.
I experience the same problem, regardless of web browser.
theschmitzer's answer didn't help me.
I found that as long as I am using the jquery javascript library the destroy method in the controller is never called.
In my case I had a conflict between the javascript libraries (jQuery and Prototype) which was hard to figure out for such a newbie. I changed completely to jQuery - as in the end of this railcast: http://railscasts.com/episodes/205-unobtrusive-javascript
I had the same problem. I was using the <%= javascript_include_tag :defaults %> as well as the jQuery library. When I removed the jQuery library, things worked. Also, you could use noConflict().
I notice that in rails 4, link_to puts the :method as a html attribute "data-method" but :confirm goes to an attribute "confirm" where the javascript needs it to be "data-confirm".
Not sure if this is a bug in rails, but you can work around it by doing this:
<%= link_to 'Destroy', user, :data => {:confirm => 'Are you sure?'}, :method => :delete %>