Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.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 使用vuejs2和曲别针获取图像url_Ruby On Rails_Vuejs2_Paperclip - Fatal编程技术网

Ruby on rails 使用vuejs2和曲别针获取图像url

Ruby on rails 使用vuejs2和曲别针获取图像url,ruby-on-rails,vuejs2,paperclip,Ruby On Rails,Vuejs2,Paperclip,我正在使用回形针、rails和vue。我的问题是如何使用vuejs2获取图像的url app.js var posts = #{ sanitize @posts.to_json } var app = new Vue({ el: '#app', data: { posts: posts } }) app.haml #app %div{ 'v-for' => 'post in posts' } %img{ ':

我正在使用回形针、rails和vue。我的问题是如何使用vuejs2获取图像的url

app.js

var posts = #{ sanitize @posts.to_json }
    var app = new Vue({
      el: '#app',
      data: {
        posts: posts
      }
    })
app.haml

#app
  %div{ 'v-for' => 'post in posts' }
    %img{ ':src' => 'post.avatar' }
职位


您需要编写一个新的
.as_json
函数或monkeypatch,让您的
Post
类阅读如下内容:

def as_vue_json
  { id: id, 
    title: title, 
    avatar_url: avatar.url(:original),
    description: description }
end
def as_vue_json
  { id: id, 
    title: title, 
    avatar_url: avatar.url(:original),
    description: description }
end