【发布时间】:2010-07-19 04:35:16
【问题描述】:
我有以下。每篇文章都有一个标题和一个正文,以及最多三个网址。我想将网址存储在不同的表中。因此,在我的表单中,我有一个网址字段。但是它们不起作用,只有文章字段被输入到数据库中。我应该如何指定它们?有好心人能帮我解决这个问题吗?
class Article
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
has n, :urls, through => Resource
end
class Url
include DataMapper::Resource
property :id, Serial
property :url_01, String
property :url_02, String
property :url_03, String
belongs_to :article
end
post '/create' do
@article = Article.new(params[:article])
if @article.save
redirect "/articles"
else
redirect "/articles/new"
end
end
--------------------------------------
<form action="/create" method="post">
<p>
<label>Article Title</label>
<input type="text" name="article[title]">
</p>
<p>
<label>Article Body</label>
<input type="text" name="article[body]">
</p>
<p>
<label>Url</label>
<input type="text" name="article[url_01]">
</p>
<p>
<input type="submit">
</p>
【问题讨论】:
标签: ruby sinatra datamapper