ruby - save a belongs to object with sinatra -


i'm building blog posts app sinatra. each post have many comments. can create post comments doesn't want create, don't know why.

main.rb

get "/"   @posts = post.all   haml :index end  post '/new/post'   post.create params['post']   redirect to('/') end   post '/:id'   post.get(params[:id]).comments.create(params['comment'])   redirect to('/') end  datamapper.setup(:default, env['database_url'] || "sqlite3://#{dir.pwd}/development.db")  class post   include datamapper::resource   property :id,              serial   property :title,           string   property :content,         string   property :photo,           string   property :rating,          integer   has n, :comments, :constraint => :destroy  end  class comment   include datamapper::resource   property :id,              serial   property :content,         string   belongs_to :post  end datamapper.finalize 

index.haml

 %form.new{:action => "/new/post", :method => "post"}   %input{:name => "post[title]", :type => "text"}/   %input{:name => "post[content]", :type => "text"}/   %input{:type => "submit", :value => "publier"}/  %form.new{:action => "/#{post.id}", :method => "get"}   %input{:name => "_method", :type => "hidden", :method => "post"}    %input{:content => "comment[content]", :type => "text"}/   %input.button{:type => "submit", :value => "commenter !"} 

in form, method get. in app post.

form.new{:action => "/#{post.id}", :method => "post"} 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -