Im working on a collaborative project. Today I pulled down the updated files. One of the guys started working on displaying coordinates on a map using gmaps4rails. The weird part is he put the html in the model. The problem is I cannot add in a database call for certain model.
here are the relationships:
Chef has many meals via chef_id
Chef has one location via chef_id
Both belong to chef
Location Model:
class Location < ActiveRecord::Base
acts_as_gmappable
belongs_to :chef
validates :chef_id, :zipcode, :address, presence: true
def gmaps4rails_address
"#{address}, #{zipcode}"
end
def gmaps4rails_infowindow
"<h1>Chef: #{chef.name} </h1>" <<
"<p>Address: #{address}, #{zipcode} </p>" <<
"<h4>Meals: #{chef.meals.meal_name}</h4>"
end
end
In other views I display chefs meals by:
<% chef.meals.limit(1).each do |meal| %>
<li><%= meal.meal_name %></li>
<li>$<%= meal.price %></li>
<% end %>
How exactly do I call chef.meals in the model and pass .limit to it.
Actually even in maps4rails 1.x, you're not compelled to put htm in model.
Documentation is here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Controller
Do it this way:
@json = User.all.to_gmaps4rails do |user, marker|
marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user})
end
So you can use partials and pass them variables