简体   繁体   中英

Ruby Syntax error, unexpected tIVAR, expecting keyword_end

I have a model Entry, and it belongs to a Journal. Journals have the ability to be public, so an entry belonging to a public journal would also be public, it would get that attribute from the journal.

I have an unless statement that just transfers it to the index unless @entry.is_public? || current_user.owns_entry? @entry unless @entry.is_public? || current_user.owns_entry? @entry

I have one method that is simply

def is_public?
  journal.public_access?
end

the other is pretty straightforward. The issue i am having is that when i try to use or instead of || it works fine, but when i use || it gives me a unexpected tIVAR, expecting keyword_end I am trying to figure out what the issue is, as rubocop tells me that i need to be using || and i want to conform to ruby conventions. Anyone know what the issue is?

In this case you need parentheses around your argument, ie current_user.owns_entry?(@entry) .

unless @entry.is_public? || current_user.owns_entry?(@entry)
  # ...
end

Generally speaking you should use parentheses except in the simplest cases, both for readability and to avoid syntax issues like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM