Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails, Creating method
    text
    copied!<p>I'm trying to create a method to run after any new user is created. Its been a while since I've used ruby so am having some trouble. </p> <p>I get this error C:/Users/antarr/SeniorProject/app/models/user.rb:9: syntax error, unexpected tASSOC, expecting keyword_then or ';' or '\n'</p> <pre><code>class User &lt; ActiveRecord::Base acts_as_authentic after_create :set_universal after_create :set_carrier after_create :set_role def set_role if User.count &gt;= 1 endself.roles &lt;&lt; "admin" else self.roles &lt;&lt; "subscriber" end end def set_universal if Channel.find(1).exist self.channels &lt;&lt; Channel.find(1) end def set_carrier self.carrier = Carrier.with_name(self.carrier_name).first end ROLES = %w[admin moderator subscriber] #Each user can subscribe to many channels has_and_belongs_to_many :channels #Each user who is a moderator can moderate many channels #has_many :channel_mods has_and_belongs_to_many :modifies , :class_name =&gt; "Channel" #Each user can receive many messages has_and_belongs_to_many :messages #Each user belongs to a carrier belongs_to :carrier #Filter users by role(s) named_scope :with_role, lambda { |role| {:conditions =&gt; "roles_mask &amp; #{2**ROLES.index(role.to_s)} &gt; 0 "} } def roles ROLES.reject { |r| ((roles_mask || 0) &amp; 2**ROLES.index(r)).zero? } end def roles=(roles) self.roles_mask = (roles &amp; ROLES).map { |r| 2**ROLES.index(r) }.sum end def role_symbols roles.map do |role| role.underscore.to_sym # NOT role.name.underscore.to_sym (role is a string) end end end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload