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? %>
<%= pluralize(@location.errors.count, “error”) %> prohibited
this
location from being saved:
<ul>
<% @location.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.number_field :id %>
<%= f.text_field :name %>
<%= f.text_field :coordinates %>
<%= f.number_field :course_id %>
<%= f.number_field :college_id %>
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:
4:
<%= pluralize(@location.errors.count, “error”) %>
prohibited this location from being saved:
Trace of template inclusion: app/views/locations/new.html.erb
Rails.root: C:/Postgrads0204
Application Trace http://localhost:3000/locations/new# | Framework
Tracehttp://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