Hello all,
This will be my 3rd month with Ruby on Rails. I do all my developing on
Mac with TextMate.
I'm now totally confused.
I have a one to one relationship. Projects and study_type
- project model -
belongs_to :study_type
- study_type model -
has_one :project
I can display correct data in my "show" method but not on the "index"
- project_controller -
def index
# SearchLogic
@projects = Project.search_all_projects(params[:search],
params[:page])
end
Without looking over all of the code here, you more than likely are
missing an :include. I've added it above.
Sorry, the only missing code would be in the project model.
- project model -
def self.search_all_projects(search, page)
# searchlogic gem used
# project_number, title, and pi_full_name are column names that are
searchable
# via search bar on index page.
project_number_or_title_or_pi_full_name_like(search).descend_by_id.paginate(:page
=> page, :per_page => 20)
end
I tried using as you said with a standard find and it didn't help.
I still get the "undefined method `name' for nil:NilClass" error.
I tried using as you said with a standard find and it didn't help.
I still get the "undefined method `name' for nil:NilClass" error.
John
That's a very common error and can happen in a number of different
situations. Are you using both searchlogic and will_paginate? Make sure
that any of your foreign keys, when called are being referenced by
key_id instead of key.id. That error has happened to me in those
particular situations. Otherwise, drill down into the error.
Troubleshoot your code in rails console and use reload! to apply some
quick fixes or when testing to quickly reload your environment.
This could mean that one of your projects does not have a study_type,
assuming it is the line containing <%= h @project.study_type.name %>
that is failing. You could replace that code with
<%=h @project.study_type.name if @project.study_type %> and see
whether one of the projects shows nothing for this cell.
Alternatively (probably also in fact) have a look a the Rails Guide on
debugging for how to debug a rails app.