Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何创建new.json.rabl_Ruby On Rails_Json_Api_Rabl - Fatal编程技术网

Ruby on rails 如何创建new.json.rabl

Ruby on rails 如何创建new.json.rabl,ruby-on-rails,json,api,rabl,Ruby On Rails,Json,Api,Rabl,我想生成new.json.rabl页面来创建新帖子 首先,我在post文件夹new.json.rabl文件中创建了 object @post attributes :content, :photo 和localhost:3000/post/new.json返回 {"post":{"content":null,"photo":null}} 如何将内容和照片值发送到rabl您的posts控制器中可能有一种新方法。在这里,如果希望rabl渲染内容和照片值,则需要放置: def new @pos

我想生成new.json.rabl页面来创建新帖子 首先,我在post文件夹new.json.rabl文件中创建了

object @post
attributes :content, :photo
和localhost:3000/post/new.json返回

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

如何将内容和照片值发送到rabl

您的posts控制器中可能有一种新方法。在这里,如果希望rabl渲染内容和照片值,则需要放置:

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

看起来您的
@post
变量是
nil
是的,它是nil我想将参数传递给iti,建议您阅读