0
다음과 같습니다. 각 기사에는 제목과 본문이 있으며 최대 세 개의 URL이 있습니다. 나는 다른 테이블에 URL을 저장하고 싶습니다. 따라서 내 양식에는 URL 필드가 있습니다. 그러나 그것들은 작동하지 않고 기사 필드 만 데이터베이스에 입력됩니다. 어떻게 지정해야합니까? 어떤 종류의 영혼이 나를 도와 줄 수 있습니까?Sinatra 및 Datamapper - 일대 다 관계 테이블에 데이터 삽입
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>
그 모양은? 입력이 데이터베이스에 저장되지 않습니다. –
위의 예에서 그는 html 형식의 필드로 "url"을 가지고 있습니다. 이 세 가지를 모두 표시하고 있다면 url.new 생성자를 HTML 양식의 세 가지로 모두 업데이트해야합니다. –