Search code examples
ruby-on-railsjsonapirabl

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


Solution

  • 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