Error is undefined method `roles' for nil:NilClass

On Sep 17, 10:03 pm, nobosh <[email protected]> wrote:
> I have a Projects View that shows a list of all projects... I want to
> be able to say per project if the currently signed in user is a member
> or not, and what there role is...
>
> In the project View I have:
> <% if team_member?(project.id, current_user) %>
>   <td>Request to Join</td>
> <% else %>
>   <td>Already Joined</td>
> <% end %>
>
> then the helper:
>
> module ProjectsHelper
>   def team_member?(project_id, current_user)
>      if
> current_user.permissions.find_by_project_id(project_id).role.try(:name).nil ?
>           true
>      else
>           false
>      end
>   end
> end
>
> *** But that errors. Can you help me out?
>
> Models:
> permission.rb
>
> class Permission < ActiveRecord::Base
>     belongs_to :user
>     belongs_to :project
>     belongs_to :role
> end
> project.rb
>
> class Project < ActiveRecord::Base
>
>     has_many :permissions
>     has_many :users, :through => :permissions
>
> end
> role.rb
>
> class Role < ActiveRecord::Base
>     has_many :permissions
> end
> user.rb
>
> class User < ActiveRecord::Base
>
>     belongs_to :instance
>     has_many :books
>     has_many :permissions
>     has_many :projects, :through => :permissions

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to