Ruby on rails 使用vuejs2和曲别针获取图像url
我正在使用回形针、rails和vue。我的问题是如何使用vuejs2获取图像的url app.jsRuby 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{ ':
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