ruby - Sinatra and Datamapper - inserting data to a one to many relationship table -


I have the title of each article and one body and up to three urls as well. I want to store the URL in a separate table. So in my form, I have a field for url. Although they are not working, only the text fields enter the database. How should I specify them? Any kind of spirit can help me with this?

  Datamapar :: resource property in class article: ID, serial property: title, string property: body, text n, url, & gt; DataMaper in Resource and Class URL: Resource Property: ID, Serial Property: url_01, String Property: url_02, Sting Property: url_03, Related to String: End of Article '/ Create' @Article = Article. News (Paramos [: Articles]) If @ article.Save Redirects / Articles "Other Redirects" / Articles / New End End ----------------------- ----- ---------- 

I believe that

 , via = => resource  

is only necessary if you have multiple- Many-to-many relationships are doing one-to-many, which I think is what you want, they do not need it.

Edit for comment:

If I were you, then I will name the name of my form field as usual and the database object Programming will be manually prepared, for example:

  & lt; Form action = "/ create" method = "post" & gt; & Lt; P & gt; & Lt; Label & gt; Article Title & lt; / Labels & gt; & Lt; Input type = "text" name = "title" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Label & gt; Article Body & lt; / Labels & gt; & Lt; Input type = "text" name = "body" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Label & gt; Url & lt; / Labels & gt; & Lt; Input type = "text" name = "url" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" & gt; & Lt; / P & gt;  

and then:

  post / create 'do article article * NY (: Title = & gt; Params [: Title] ,: body = & gt; Param [: Body]) @url = url.new (url_01 = & gt; Param [[url]) @ article.url = @ Url if @ article.save redirects "/ articles" other redirects "/ article / new" and end  

Comments