Rails syntax error in one-to-many associations exercise in Lynda Rails 3 tutorial -
what problem , how can fix it?
when in rails console run page.editors
and following syntax errors:
...simple_cms/app/models/admin_user.rb:8: syntax error, unexpected ':', expecting keyword_end scope: named, lambda {|first,last| ... ^ ...simple_cms/app/models/admin_user.rb:8: syntax error, unexpected '\n', expecting :: or '[' or '.'
here code...
admin_user.rb
class adminuser < activerecord::base attr_accessible :title, :body, :username, :first_name, :last_name # configure different table name # set_table_name("admin_users") has_and_belongs_to_many :pages scope: named, lambda {|first,last| where(:first_name => first, :last_name => last)} end
page.rb
class page < activerecord::base attr_accessible :title, :body, :name, :permalink, :position belongs_to :subject has_many :sections has_and_belongs_to_many :editors, :class_name => "adminuser" end
alter_users.rb
class alterusers < activerecord::migration def rename_table("users", "admin_users") add_column("admin_users", "username", :string, :limit => 25) change_column("admin_users", "email", :string, :limit => 100) rename_column("admin_users", "password", "hashed_password") add_column("admin_users", "salt", :string, :limit => 40) puts "*** add index ***" add_index("admin_users", "username") end def down remove_index("admin_users", "username") remove_column("admin_users", "salt") rename_column("admin_users", "hashed_password", "password") change_column("admin_users", "email", :string, :default => "", :null => false) remove_column("admin_users", "username") rename_table("admin_users", "users") end end
create_admin_users_pages_join.rb
class createadminuserspagesjoin < activerecord::migration def create_table :admin_users_pages, :id => false |t| t.integer "admin_user_id" t.integer "page_id" end add_index :admin_users_pages, ["admin_user_id", "page_id"] end def down drop_table :admin_users_pages end end
don't read below line: stack overflow wanted me add more text because question has lot of code. thought having code want me :)
remove colon on scope, , put before named:
scope: named, lambda {|first,last| ... scope :named, lambda {|first,last| ...
Comments
Post a Comment