【发布时间】:2015-04-21 23:57:22
【问题描述】:
我以前在带有 Datamapper 的 Sinatra 应用程序中使用过这种方法,没有任何问题。 现在它似乎不起作用。任何想法表示赞赏。 我的测试:
scenario 'add hashtags to posts' do
visit '/'
add_post('Stacca',
'Hello! out there',
%w(foo bar))
post = Post.first
expect(post.hashtag.map(&:text)).to include('foo')
expect(post.hashtag.map(&:text)).to include('bar')
结束
我的服务器
post '/posting' do
username = params['username']
message = params['message']
hashtag = params['hashtag'].split(' ').map do |hashtag|
hashtag.first_or_create(text: hashtag)
end
Post.create(username: username, message: message, hashtag: hashtag)
redirect to ('/')
end
我的模特:
class Post
include DataMapper::Resource
property :id, Serial
property :username, String
property :message, String
has n, :hashtag, through: Resource
end
和:
class Hashtag
include DataMapper::Resource
has n, :posts, through: Resource
property :id, Serial
property :text, String
end
谢谢
【问题讨论】:
标签: ruby sinatra datamapper