有什么问题,我该如何解决?
当我在rails控制台中运行时page.editors
并得到以下语法错误:
...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 '.'
这是我的代码...
admin_user.rb
class AdminUser < ActiveRecord::Base
attr_accessible :title, :body, :username, :first_name, :last_name
# To configure a 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
页面.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 up
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 "*** About to add an 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 up
create_table :admin_users_pages, :id => false do |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
不要在这行下面阅读:Stack Overflow 想让我添加更多文本,因为这个问题有很多代码。但我认为拥有代码会帮助那些想帮助我的人:)