简体   繁体   中英

How to make new.json.rabl

I want to generate new.json.rabl page to create new post first of all i created in post folder new.json.rabl file

object @post
attributes :content, :photo

and localhost:3000/post/new.json return

{"post":{"content":null,"photo":null}}

how can i send content and photo values to rabl

You probably have a method new in your posts controller. There, if you want rabl to render the content and photo values, you need to put:

def new
  @post = Post.new(content: "some_content", photo: "some_photo")
  render('path_to_your_rabl_file', formats: :json) # or respond_with(@post) if the routes are correct
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM