Ruby on Rails
Tuesday, April 2, 2013
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:
-- 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.jsondef index@locations = Location.all@json = Location.all.to_gmaps4railsendrespond_to do |format|format.html # index.html.erbformat.json { render json: @locations }endend# GET /locations/1# GET /locations/1.jsondef show@location = Location.find(params[:id])@json = Location.all.to_gmaps4railsrespond_to do |format|format.html # show.html.erbformat.json { render json: @location }endend# GET /locations/new# GET /locations/new.jsondef new@location = Location.new@json = Location.all.to_gmaps4railsrespond_to do |format|format.html # new.html.erbformat.json { render json: @location }endend# GET /locations/1/editdef edit@location = Location.find(params[:id])@json = Location.all.to_gmaps4railsend# POST /locations# POST /locations.jsondef create@location = Location.new(params[:location]) @json = Location.all.to_gmaps4railsrespond_to do |format|if @location.saveformat.html { redirect_to @location, notice: 'Location was successfully created.' }format.json { render json: @location, status: :created, location: @location }elseformat.html { render action: "new" }format.json { render json: @location.errors, status: :unprocessable_entity }endendend# PUT /locations/1# PUT /locations/1.jsondef update@location = Location.find(params[:id])@json = Location.all.to_gmaps4railsrespond_to do |format|if @location.update_attributes(params[:location]) format.html { redirect_to @location, notice: 'Location was successfully updated.' }format.json { head :no_content }elseformat.html { render action: "edit" }format.json { render json: @location.errors, status: :unprocessable_entity }endendend# DELETE /locations/1# DELETE /locations/1.jsondef destroy@location = Location.find(params[:id])@location.destroy@json = Location.all.to_gmaps4railsrespond_to do |format|format.html { redirect_to locations_url }format.json { head :no_content }endendand 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
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?CheersJ
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment