I need a way to determine is a User has a Project.
My User model has a has_one :project declaration
and the Project model as a belongs_to :User declaration.
I want to set up a toggle state in my app/views/users/show.html.erb file using this logic…
<div id="snapshot">
<h2>Project Snapshot</h2>
<% if has_project? %>
<% render 'projects/project_overview' %>
<% else %>
<% render 'projects/no_project' %>
<% end %>
</div>
The code for the ProjectsHelper method is…
<% def has_project %>
<% current_user.project(params[:user_id]) %>
<% end %>
I need to know why this isn’t rendering either option? The view displays without error.
Question has been updated from original.
Remove the equals sign in the statement.
Your code has:
Should be:
Edit
Try changing your
<% if has_project? %>to<% if current_user.project %>(because all it seems you want to do is query whether the current user has an associated project or not) and remove the helper method. See the Rails API entry on ActiveRecord::Associations::ClassMethods to find out what methods are provided when you create an association.