Hi. I am new to rails and am hoping someone can help me understand why I
am getting a certain error.  I have gone through the Agile Web
Development Book and am now trying to build a basic app (job board) to
try something "real world."
I have a form where I collect the job details.  In the form is a select
statement which pulls categories from the DB.  The categories are in an
instance variable that I create in the index method.  When I load the
form, the categories are loaded correctly.  However, then I added
validation, and when a validator kicks, I get a NoMethodError (You have
a nil object when you didn''t expect it! You might have expected an
instance of Array. The error occurred while evaluating nil.inject).
It points me to the select statement in  my form as the culprit.  So, it
seems that the instance variable is not populated, after the error, when
its part of the index method.  I think I confirmed this by putting the
instance variable inline, before the select statement, in the form.
Then everything worked as expected.
I really am just trying to learn what I am doing wrong and why that
isn''t filling the instance variable with the categories.  Any education
is appreciated!!
Thanks
Josh
Here is relevant code:
----------------------------------------------------------
index.rhtml(view)
<div>
  <%= error_messages_for ''full_time_job'' %>
<fieldset>
  <legend>Enter Job</legend>
   <%form_for :full_time_job, :url => { :action => :save_job} do
|form|%>
  <p>
    <label for ="company">Company</label>
    <%= form.text_field  :company, :size =>100 %>
  </p>
  <p>
    <label for ="url">Website</label>
    <%= form.text_field  :url, :size =>200 %>
  </p>
  <p>
    <label for ="title">Job Title</label>
    <%= form.text_field  :title, :size =>255 %>
  </p>
  <p>
    <label for ="location">Job Location</label>
    <%= form.text_field  :location, :size =>100 %>
  </p>
  <p>
    <label for ="description">Description</label>
    <%= form.text_area  :description, :rows =>3, :cols =>40 %>
  </p>
  <p>
    <label for ="category">Category</label>
    <%=form.collection_select
(:fulltimecategory_id,@categories,:id,:name) %>
  </p>
  <p>
    <label for ="apply">How to Apply</label>
    <%= form.text_field  :apply, :size =>100 %>
  </p>
  <%= submit_tag "Save Job", :class => "submit" %>
  <%end%>
</fieldset>
</div>
----------------------------------------------
full_time_add_controller.rb (controller)
class FullTimeAddController < ApplicationController
  def save_job
    @full_time_job = FullTimeJob.new(params[:full_time_job])
    if @full_time_job.save
    else
      render :action => :index
    end
  end
  def index
    @categories = FullTimeCategory.find(:all, :order =>
"display_order")
  end
end
--------------------------------------------------
full_time_job.rb (Model)
class FullTimeJob < ActiveRecord::Base
  belongs_to  :full_time_category
  validates_presence_of :company
  def self.find_jobs
    find(:all, :order => "created_at")
  end
end
-- 
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---