Hi All, just in a spot of bother with this gem, I am trying to create a new location and get the above msg. here is my controller: class LocationsController < ApplicationController # GET /locations # GET /locations.json def index @locations = Location.all @json = Location.all.to_gmaps4rails end respond_to do |format| format.html # index.html.erb format.json { render json: @locations } end end # GET /locations/1 # GET /locations/1.json def show @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| format.html # show.html.erb format.json { render json: @location } end end # GET /locations/new # GET /locations/new.json def new @location = Location.new @json = Location.all.to_gmaps4rails respond_to do |format| format.html # new.html.erb format.json { render json: @location } end end # GET /locations/1/edit def edit @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails end # POST /locations # POST /locations.json def create @location = Location.new(params[:location]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.save format.html { redirect_to @location, notice: ''Location was successfully created.'' } format.json { render json: @location, status: :created, location: @location } else format.html { render action: "new" } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # PUT /locations/1 # PUT /locations/1.json def update @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.update_attributes(params[:location]) format.html { redirect_to @location, notice: ''Location was successfully updated.'' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # DELETE /locations/1 # DELETE /locations/1.json def destroy @location = Location.find(params[:id]) @location.destroy @json = Location.all.to_gmaps4rails respond_to do |format| format.html { redirect_to locations_url } format.json { head :no_content } end end and the _form I use to create the new location: <%= form_for(@location) do |f| %> <% if @location.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@location.errors.count, "error") %> prohibited this location from being saved:</h2> <ul> <% @location.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :id %><br /> <%= f.number_field :id %> </div> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> <div class="field"> <%= f.label :coordinates %><br /> <%= f.text_field :coordinates %> </div> <div class="field"> <%= f.label :course_id %><br /> <%= f.number_field :course_id %> </div> <div class="field"> <%= f.label :college_id %><br /> <%= f.number_field :college_id %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> This is the error msg in full: NoMethodError in Locations#new Showing *C:/Postgrads0204/app/views/locations/_form.html.erb* where line *#1 * raised: undefined method `model_name'' for NilClass:Class Extracted source (around line *#1*): 1: <%= form_for(@location) do |f| %> 2: <% if @location.errors.any? %> 3: <div id="error_explanation"> 4: <h2><%= pluralize(@location.errors.count, "error") %> prohibited this location from being saved:</h2> Trace of template inclusion: app/views/locations/new.html.erb Rails.root: C:/Postgrads0204 Application Trace <http://localhost:3000/locations/new#> | Framework Trace<http://localhost:3000/locations/new#> | Full Trace <http://localhost:3000/locations/new#> app/views/locations/_form.html.erb:1:in `_app_views_locations__form_html_erb___82209480_46213008'' app/views/locations/new.html.erb:3:in `_app_views_locations_new_html_erb___810294894_46206828'' Any Ideas where am I going wrong? Cheers J -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/aCsSvcAzghAJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Apr-02 14:47 UTC
Re: gmaps4rails: undefined method `model_name'' for NilClass:Class
On 2 April 2013 15:34, Jax <javier_rossetti1972-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > NoMethodError in Locations#new > > Showing C:/Postgrads0204/app/views/locations/_form.html.erb where line #1 > raised: > > undefined method `model_name'' for NilClass:Class > > Extracted source (around line #1): > > 1: <%= form_for(@location) do |f| %>The problem is nothing to do with the gem. @location is nil. Are you passing the value across when you render the form? It seems to be the only bit of code that you have not shown us. See http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials for how to pass data to the form. Also have a look at the Rails Guide on debugging with will show you techniques that you can use to debug your code. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jax
2013-Apr-02 16:06 UTC
Re: gmaps4rails: undefined method `model_name'' for NilClass:Class
Hi Colin, Thank you for your comment, I was actually missing a "end" tag to close off the class in the controller! Cheers anyway J On Tuesday, April 2, 2013 3:34:11 PM UTC+1, Jax wrote:> > Hi All, > > just in a spot of bother with this gem, I am trying to create a new > location and get the above msg. > > here is my controller: > > class LocationsController < ApplicationController > # GET /locations > # GET /locations.json > > def index > @locations = Location.all > @json = Location.all.to_gmaps4rails > end > respond_to do |format| > format.html # index.html.erb > format.json { render json: @locations } > end > end > > # GET /locations/1 > # GET /locations/1.json > def show > @location = Location.find(params[:id]) > @json = Location.all.to_gmaps4rails > respond_to do |format| > format.html # show.html.erb > format.json { render json: @location } > end > end > > # GET /locations/new > # GET /locations/new.json > def new > @location = Location.new > @json = Location.all.to_gmaps4rails > > respond_to do |format| > format.html # new.html.erb > format.json { render json: @location } > end > end > > # GET /locations/1/edit > def edit > @location = Location.find(params[:id]) > @json = Location.all.to_gmaps4rails > end > > # POST /locations > # POST /locations.json > def create > @location = Location.new(params[:location]) > @json = Location.all.to_gmaps4rails > respond_to do |format| > if @location.save > format.html { redirect_to @location, notice: ''Location was > successfully created.'' } > format.json { render json: @location, status: :created, location: > @location } > else > format.html { render action: "new" } > format.json { render json: @location.errors, status: > :unprocessable_entity } > end > end > end > > # PUT /locations/1 > # PUT /locations/1.json > def update > @location = Location.find(params[:id]) > @json = Location.all.to_gmaps4rails > respond_to do |format| > if @location.update_attributes(params[:location]) > format.html { redirect_to @location, notice: ''Location was > successfully updated.'' } > format.json { head :no_content } > else > format.html { render action: "edit" } > format.json { render json: @location.errors, status: > :unprocessable_entity } > end > end > end > > # DELETE /locations/1 > # DELETE /locations/1.json > def destroy > @location = Location.find(params[:id]) > @location.destroy > @json = Location.all.to_gmaps4rails > respond_to do |format| > format.html { redirect_to locations_url } > format.json { head :no_content } > end > end > > and the _form I use to create the new location: > > <%= form_for(@location) do |f| %> > <% if @location.errors.any? %> > <div id="error_explanation"> > <h2><%= pluralize(@location.errors.count, "error") %> prohibited > this location from being saved:</h2> > > <ul> > <% @location.errors.full_messages.each do |msg| %> > <li><%= msg %></li> > <% end %> > </ul> > </div> > <% end %> > > <div class="field"> > <%= f.label :id %><br /> > <%= f.number_field :id %> > </div> > <div class="field"> > <%= f.label :name %><br /> > <%= f.text_field :name %> > </div> > <div class="field"> > <%= f.label :coordinates %><br /> > <%= f.text_field :coordinates %> > </div> > <div class="field"> > <%= f.label :course_id %><br /> > <%= f.number_field :course_id %> > </div> > <div class="field"> > <%= f.label :college_id %><br /> > <%= f.number_field :college_id %> > </div> > <div class="actions"> > <%= f.submit %> > </div> > <% end %> > > This is the error msg in full: > > NoMethodError in Locations#new > > Showing *C:/Postgrads0204/app/views/locations/_form.html.erb* where line * > #1* raised: > > undefined method `model_name'' for NilClass:Class > > Extracted source (around line *#1*): > > 1: <%= form_for(@location) do |f| %> > > 2: <% if @location.errors.any? %> > > 3: <div id="error_explanation"> > > 4: <h2><%= pluralize(@location.errors.count, "error") %> prohibited this location from being saved:</h2> > > Trace of template inclusion: app/views/locations/new.html.erb > > Rails.root: C:/Postgrads0204 > Application Trace <http://localhost:3000/locations/new#> | Framework Trace<http://localhost:3000/locations/new#> > | Full Trace <http://localhost:3000/locations/new#> > > app/views/locations/_form.html.erb:1:in `_app_views_locations__form_html_erb___82209480_46213008'' > > app/views/locations/new.html.erb:3:in `_app_views_locations_new_html_erb___810294894_46206828'' > > > Any Ideas where am I going wrong? > > Cheers > > J >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/AT0h2_FxC80J. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2013-Apr-02 16:37 UTC
Re: Re: gmaps4rails: undefined method `model_name'' for NilClass:Class
On 2 April 2013 17:06, Jax <javier_rossetti1972-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Hi Colin, > > Thank you for your comment, I was actually missing a "end" tag to close off > the class in the controller!A missing end tag in the controller code gave you the error "undefined method `model_name'' for NilClass:Class"? That is unusual. I would have expected to get a syntax error about the missing end when the class was loaded. Colin> > Cheers anyway > > J > > > On Tuesday, April 2, 2013 3:34:11 PM UTC+1, Jax wrote: >> >> Hi All, >> >> just in a spot of bother with this gem, I am trying to create a new >> location and get the above msg. >> >> here is my controller: >> >> class LocationsController < ApplicationController >> # GET /locations >> # GET /locations.json >> >> def index >> @locations = Location.all >> @json = Location.all.to_gmaps4rails >> end >> respond_to do |format| >> format.html # index.html.erb >> format.json { render json: @locations } >> end >> end >> >> # GET /locations/1 >> # GET /locations/1.json >> def show >> @location = Location.find(params[:id]) >> @json = Location.all.to_gmaps4rails >> respond_to do |format| >> format.html # show.html.erb >> format.json { render json: @location } >> end >> end >> >> # GET /locations/new >> # GET /locations/new.json >> def new >> @location = Location.new >> @json = Location.all.to_gmaps4rails >> >> respond_to do |format| >> format.html # new.html.erb >> format.json { render json: @location } >> end >> end >> >> # GET /locations/1/edit >> def edit >> @location = Location.find(params[:id]) >> @json = Location.all.to_gmaps4rails >> end >> >> # POST /locations >> # POST /locations.json >> def create >> @location = Location.new(params[:location]) >> @json = Location.all.to_gmaps4rails >> respond_to do |format| >> if @location.save >> format.html { redirect_to @location, notice: ''Location was >> successfully created.'' } >> format.json { render json: @location, status: :created, location: >> @location } >> else >> format.html { render action: "new" } >> format.json { render json: @location.errors, status: >> :unprocessable_entity } >> end >> end >> end >> >> # PUT /locations/1 >> # PUT /locations/1.json >> def update >> @location = Location.find(params[:id]) >> @json = Location.all.to_gmaps4rails >> respond_to do |format| >> if @location.update_attributes(params[:location]) >> format.html { redirect_to @location, notice: ''Location was >> successfully updated.'' } >> format.json { head :no_content } >> else >> format.html { render action: "edit" } >> format.json { render json: @location.errors, status: >> :unprocessable_entity } >> end >> end >> end >> >> # DELETE /locations/1 >> # DELETE /locations/1.json >> def destroy >> @location = Location.find(params[:id]) >> @location.destroy >> @json = Location.all.to_gmaps4rails >> respond_to do |format| >> format.html { redirect_to locations_url } >> format.json { head :no_content } >> end >> end >> >> and the _form I use to create the new location: >> >> <%= form_for(@location) do |f| %> >> <% if @location.errors.any? %> >> <div id="error_explanation"> >> <h2><%= pluralize(@location.errors.count, "error") %> prohibited >> this location from being saved:</h2> >> >> <ul> >> <% @location.errors.full_messages.each do |msg| %> >> <li><%= msg %></li> >> <% end %> >> </ul> >> </div> >> <% end %> >> >> <div class="field"> >> <%= f.label :id %><br /> >> <%= f.number_field :id %> >> </div> >> <div class="field"> >> <%= f.label :name %><br /> >> <%= f.text_field :name %> >> </div> >> <div class="field"> >> <%= f.label :coordinates %><br /> >> <%= f.text_field :coordinates %> >> </div> >> <div class="field"> >> <%= f.label :course_id %><br /> >> <%= f.number_field :course_id %> >> </div> >> <div class="field"> >> <%= f.label :college_id %><br /> >> <%= f.number_field :college_id %> >> </div> >> <div class="actions"> >> <%= f.submit %> >> </div> >> <% end %> >> >> This is the error msg in full: >> >> NoMethodError in Locations#new >> >> Showing C:/Postgrads0204/app/views/locations/_form.html.erb where line #1 >> raised: >> >> undefined method `model_name'' for NilClass:Class >> >> Extracted source (around line #1): >> >> 1: <%= form_for(@location) do |f| %> >> >> 2: <% if @location.errors.any? %> >> >> 3: <div id="error_explanation"> >> >> 4: <h2><%= pluralize(@location.errors.count, "error") %> prohibited >> this location from being saved:</h2> >> >> Trace of template inclusion: app/views/locations/new.html.erb >> >> Rails.root: C:/Postgrads0204 >> >> Application Trace | Framework Trace | Full Trace >> >> app/views/locations/_form.html.erb:1:in >> `_app_views_locations__form_html_erb___82209480_46213008'' >> >> app/views/locations/new.html.erb:3:in >> `_app_views_locations_new_html_erb___810294894_46206828'' >> >> >> Any Ideas where am I going wrong? >> >> Cheers >> >> J > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/AT0h2_FxC80J. > > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Rajesh G.
2013-Oct-31 05:33 UTC
Re: gmaps4rails: undefined method `model_name'' for NilClass:Class
i am using google maps for my project in rails 4, ruby 2, and gmaps4rails ''1.5.6'' but the problem is i am not getting marker at center of the map as well as the zoom in zoom out side bar is also not coming. If any one have any idea about this problem please reply? Model Action acts_as_gmappable def gmaps4rails_address html = full_address(city_id,state_id,country_id) self.location = (location + html) location end def full_address(city_id,state_id,country_id) city_name = MdmCity.get_city_name(city_id) state_name = MdmState.get_state_name(state_id) country_name = MdmCountry.get_country_name(country_id) html = "#{city_name} #{state_name} #{country_name}" html end Controller Action def edit_content @location_json = SeoContent.where(:id => params[:id]).first.to_gmaps4rails end VIEW <%= gmaps4rails(@location_json) %> Issues for me. 1) Zoom In and Zoom out bar is not coming. 2) Marker is not coming at center. 3) How to give Info window. 4) How to raise that address is Invalid, which is not present on google map (Eg:kdjfkdfhdkfhd) 5) Why this action (def gmaps4rails_address) is calling automatically. 6) I want to call def gmaps4rails_address from update action too how ? 7) Map is coming only one forth ?why 8) Can i show directions on map ? Thanks Attachments: http://www.ruby-forum.com/attachment/8878/gmap.png -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/43f91518a7282838c0e07c9f6003d04f%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Apparently Analagous Threads
- undefined method `model_name' for NilClass:Class
- [announcement] Google Maps + Rails 3 = gmaps4rails
- gmaps4rails "acts_as_gmappable" error
- undefined method `model_name' for NilClass:Class in a form_for
- undefined method `model_name' for NilClass:Class in rails 3.0.0