我belongs_to
与同一个模型有多种关系.在两个用户之间建模消息如下(在Message
模型中):
belongs_to :to, :class_name => 'User', :foreign_key => 'to_id'
belongs_to :from, :class_name => 'User', :foreign_key => 'from_id'
attr_accessible :to, :from # ...
Run Code Online (Sandbox Code Playgroud)
相应的has_many
调用在User
模型中.除了以下弃用警告(对于两者from_id
和to_id
),一切都在我需要的规范和控制台中工作:
DEPRECATION WARNING: You're trying to create an attribute `from_id'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer`
Run Code Online (Sandbox Code Playgroud)
相关规范如下:
it "can associate users" do
User.delete(:all)
ufrom = FactoryGirl.create(:DrKevorkian)
ufrom.save!
uto = FactoryGirl.create(:JohnSmith)
uto.save!
m = Message.new
m.from = ufrom # <-- Warning …
Run Code Online (Sandbox Code Playgroud) 根据Ryan Bates的RailsCast(在Linux Mint 12下),我已经安装了防护和spork,并且防护过程在启动后立即显示"已杀死".运行"bundle exec guard --verbose"给出:
bundle exec guard --verbose DEBUG(12:17:27):命令执行:which notify-send
Guard使用NotifySend发送通知.
警卫正在观看'path_to_project'
DEBUG(12:17:27):Hook:为Guard :: Spork执行了start_begin
DEBUG(12:17:27):命令执行:ps aux | awk'/ spork/&&!/ awk/{print $ 2;}'
DEBUG(12:17:27):使用PID:8884杀死Spork服务器
杀害
我已经尝试调整guard gem文档的"高级Linux系统配置"(max_queued_events和max_user_instances,max_users_watches)中的值.没有比所有人的默认值高得多的快乐.
有任何想法吗?如果是这样,请提前感谢.到目前为止,Google-fu对此特定问题没有任何帮助.
以下内容使我印象深刻,但确实有效。有没有办法让烧瓶轻松地使用相同的资源类来处理两种标准的get方法(即获得所有东西并获得一件物品)?
谢谢。
from flask_restful import Resource
# ...
class People(Resource):
def get(self):
return [{'name': 'John Doe'}, {'name': 'Mary Canary'}]
class Person(Resource):
def get(self, id):
return {'name': 'John Doe'}
# ...
api.add_resource(People, '/api/people')
api.add_resource(Person, '/api/people/<string:id>')
Run Code Online (Sandbox Code Playgroud)