This is going to be a really dumb question, and I almost hate myself for asking it, but here goes.
When I run my Cucumber test, I’m getting a “syntax error, unexpected ‘)'” with the following code:
inside my user model:
def member?(gallery)
array = []
self.groups.each do |group|
array << group.id
end
if array.include?(gallery.group.id)
true
end
end
And in my view:
<ul>
<% @galleries.each do |gallery| %>
<% if current_user.member?(gallery) %>
<li>
<%= link_to gallery.title, gallery %>
</li>
<% end %>
<% end %>
</ul>
EDIT: Here is the important part of the error in full:
~/Coding/Rails/galleryTest/app/views/galleries/index.html.erb:8: syntax error, unexpected ')', expecting keyword_then or ';' or '\n'
... current_user.member? gallery );@output_buffer.safe_concat('
... ^
~/Coding/Rails/galleryTest/app/views/galleries/index.html.erb:13: syntax error, unexpected keyword_end, expecting ')'
'); end
^
EDIT 2: Here is the error when removing the ‘=’:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id (ActionView::Template::Error)
./app/models/user.rb:18:in `member?'
I have tried a few different things, and I’ve got to be missing something really trivial. Another pair of eyes would be greatly appreciated.
Thank you very much.
should be:
Not that there is no
=, it means output and your code is trying to output the response of the if block.