想要从客户端获取数据,通过使用创建操作,如何通过在创建函数中使用 post 方法获取数据,我的观点是我如何通过 post 方法使用 create 函数从客户端获取数据
def create
respond_to do |format|
@post = Post.new(params[:post])
if @post.save
flash[:notice] = "Prayer Successfully created."
@posts = Post.paginate(page: params[:page],:per_page => 5)
format.json{ render :json => @post, :only=> :content, :location => @post }
else
flash[:notice] = "Error"
@posts = Post.paginate(page: params[:page],:per_page => 5)
format.json{ render :json => @post, :status => :created }
end
end
end
def create_a_post
content = JSON.parse request.body.read
@post = Post.new[:content]
@post.save
end
我的代码从客户端获取数据是正确还是错误
任何人请解决我的 pblm