Google-maps-for-Rails without a Model - ruby-on-rails

Sorry to be newbie, but i wanna draw your attention to my problem while using gmaps4rails - great gem.
In my app there is no database backend. Actually i just want to collect markers like this:
<% markers=[]%>
<% #search.each do |dish| %>
<% if (not dish.restaurant.nil?)
restaurant=Restaurant.where( :id => dish.restaurant["Id"])
markers<< {:longitude => restaurant.lng , :latitude=> restaurant.lat}
end%>
<div id="dish_listed"><%= render 'dish_listed', :dish => dish %></div>
<% end %>
<%= gmaps4rails(markers.to_json) %>
Unfortunately it displays a gray rectangular whithout a map *(
I`ve managed to follow the steps from Wiki (i did it several times *))))
When i do
markers.to_json
i get
"[{\"longitude\":"30.252442359924316",\"latitude\":"59.92999013067258"}]"
And i have no idea why kind of code
<%= gmaps4rails('[{\"lng\":"30.252442359924316",\"lat\":"59.92999013067258"}]') %>
doesnt work? Where should it be initialized? Or what magic steps did i forget? I also forked a project by thasuresh. Started it and the removed everything from the model, and pushed my markers there, and it displayed me just what i wanted.
But i still cant reach the same result on the project i write by my self!!!
-----And now i`m sitting here and waiting for flying tomatos *)))-----
PS
rails 3.1rc5
gmaps4rails 0.10.2
BTW Could it be no gmappable model?

This works:
<%= gmaps4rails('[{"lng":"30.252442359924316","lat":"59.92999013067258"}]') %>
There are still little fixes to do for Rails 3.1, some threads are open on github.
To adjust the zoom level with one marker, check this question.

Related

Hi, i am quite new to web developing. So forgive me for any stupid question

I am trying to build an ecommerce page using rails. In my products page I want to add products with an image, description, color and price. Everything works properly except for the images. I am not able to assign proper image to the desired product. If i use this syntax : <%= image_tag("/assets/6.jpeg", class: "img-fluid") %>, then this particular image is assigned to all other products and it's definitely not logical!
I have already added the images which I need for my project in the app/assets/images folder. I want to have the possibility to dynamically add/modify the photos on my page.
Please help me how to solve this issue. Thanking you guys in advance!
if images file are saved 1.jpeg-?.jpeg you could loop say
<% #product.each_with_index do |product, index| %>
<% i = index + 1 %>
<%= image_tag("assets/#{i}.jpeg"), class: 'image-fluid' %>
<% end %>
I mean for what you're asking this would work but is probably not the best way to go about this.

How do I get sidebar to be rendered on left when viewing object?

I'm pretty new to rails so sorry if this I'm not clear. I have an object called projects in layouts I have _left_column.html.erb that adds stuff to the left column based on what page I'm on. In this case the stuff is info of other objects that are associated with it (things like tasks).
Screenshot:
I works as shown but only for the project with id of 1. I'm not sure how to get this to work on all projects. Thanks!
I'll try to give some tips for your code
<% case request.path.split('?').first.to_s %>
<% when 'projects/1' %>
# this is the problem,
# all code below when 'projects/1' only running if projects equal to 1
# if you want all code below running you can try remove the logic when
<% end %>
<% end %>

Ruby on Rails image loop

I'm attempting to create a loop which shows stars as reviews are placed for a product, i have it so that it shows the rating as a number however i wish for it to display an image relating to the rating number,
i've currently got
<%=product.no_of_stars.to_i do image_tag "star-on.png" end %>
however it just displays the rating figure and not the number, no doubt I've missed something simple.
I've researched other questions and they state that should be enough for what i want, but of course its not working as expected.
Thanks, Ben.
The above answer is not quite correct. The problem is that Integer#times returns the integer it was called on, so you will still get 5 as the result. Try
<% product.no_of_starts.to_i.times do %>
<%= image_tag "star-on.png" %>
<% end %>
Try this.
<%=product.no_of_stars.to_i.times do image_tag "star-on.png" end %>
You are missing the times method. This is what allows you to run the number as a loop over and over again (super simplification).

How do I access uploaded images in refinery cms?

I'm pretty sure that there should be an easy way of doing this. I already tried out to override the models and discovered that the imagines seem to get saved in the database.
All i want it to be able to show all the oploaded images in the application view, so that they can be displayed on every page.
Currently I am new to Rails, I would be thankful for an easy guide or at least some hints.
They're saved as Image model instances and you can use the image_fu view helper to render them in whatever size you need. So in your view just do something along the lines of
<% Image.all.each do |image| %>
<%= image_fu image, "100x100", :id => dom_id(image) %>
<% end %>

Rails 3 : CacheHelper, cached block doesn't render in the production environment

I hope that someone may help me because I'm facing such a strange behavior concerning Rails 3.
Here's the problem :
I've developed a blog in which each article may have one or more tags.
I used a classic method to assign tags to each article, using a third model: taggings which makes the bridge between an Article and its tags usign their respective ids.
Then, in the index page of my articles, I have a sidebar showing all the tags.
So far everything works well in the Development environment: all the tags show up. But... When I launch the site in a production environment, no tags appear at all but they do are saved in the production database.
Here's the code I use within my view to show up the tags:
<ul id="tags">
<% cache("all_tags") do %>
<% for tag in Tag.find(:all, :order => "name") %>
<li><%= link_to "#{tag.name}", tag_path(tag) %></li>
<% end %>
<% end %>
</ul>
Also I've tried to just put something like
<%= Tag.all %>
And it seems to produce a strange result for each tag saved in the database:
#<Tag:some_alpha_numeric_caracters>
Does anyone have an idea about this strange behavior?
Thanks a lot for all your help you may bring to me :)
Regards,
M. Millet
Ok so I finally found the problem. I had to simply delete:
<% cache("all_tags") do %>
It seems that what the cache contains (usign the cache function) is not rendered in production. But I don't know why.. So even if I've resolved my problem it would be great if anyone can explain me why the cache block doesn't render in a production environment.
Thanks :)
Best regards,
Kulgar.

Resources