Suchfunktion in Rails

Kalito

Erfahrenes Mitglied
Hallo,

habe ein Jobportal gebaut und hänge gerade an der Suchfunktion. Wenn ich es aufrufe kommt folgende Fehlermeldung:

RuntimeError in JobsController#create

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Rails.root: C:/Sites/rp_on_rails

Application Trace | Framework Trace | Full Trace
app/controllers/jobs_controller.rb:56:in `create'

folgenden Code habe ich:

Model:
PHP:
def self.search(params)
	find(:all, :conditions => ["title LIKE ? AND location LIKE ?", "%#{params[:title]}%", "%#{params[:location]}%"])
  end
Controller
PHP:
def search
	@job_search = Job.new
	@jobs = Job.search(params)
  end

View
PHP:
<h1>Jobsuche</h1>
<%= form_for(@job_search) do |f| %>
  <div class="field">
    <%= f.label :title, "Titel des Stellenangebots" %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :date_begin, "Fruehester Beginn der Anstellung" %><br />
    <%= f.date_select :date_begin, start_year: Time.now.year - 1, end_year: Time.now.year + 1, order: [:month, :year] %>
  </div>
  <div class="field">
    <%= f.label :location, "Ort der Anstellung" %><br />
    <%= f.text_field :location %>
  </div>
  <div>
	<%=f.label:company, "Unternehmen" %><br/>
	<%=f.collection_select :company_id, Company.all, :id, :name %> 
  </div>
  <div class="field">
    <%= f.label :activity, "Kurze Taetigkeitsbeschreibung" %><br />
    <%= f.text_field :activity %>
  </div>
  <div class="field">
    <%= f.label :kind, "Anstellungsverhaeltnis" %><br />
    <%= f.select :kind, App::Config.contract_types  %>
  </div>
  <div class="field">
    <%= f.label :degree, "Abschluss" %><br />
    <%= f.select :degree, App::Config.degree_types %>
  </div>
  <div class="actions">
    <%= f.submit "Suchen"%>
  </div>
<% end %>
<table>
  <tr>
    <th>Company</th>
    <th>Title</th>
    <th>Date begin</th>
    <th>Location</th>
    <th>Kind</th>
    <th>Degree</th>
	<th></th>
  </tr>

<% @jobs.each do |job| %>
  <tr>
    <td><%= job.title %></td>
    <td><%= job.date_begin %></td>
    <td><%= job.location %></td>
    <td><%= job.kind %></td>
    <td><%= job.degree %></td>
    <td><%= link_to 'Show', job %></td>
  </tr>
<% end %>
</table>

Wie kann ich den Fehler beheben?
 
Zurück