1
我開始使用Socialization寶石。 因此,創建的用戶模型色器件:社會化喜歡
class User < ActiveRecord::Base
has_many :posts
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable
acts_as_follower
acts_as_followable
acts_as_liker
end
然後創建後與支架:
class Post < ActiveRecord::Base
belongs_to :user
acts_as_likeable
end
我想允許用戶像帖子。但我不知道如何用像按鈕創建視圖,也不知道如何爲喜歡編寫方法。請舉個小例子。我是新的導軌
我在veiw/posts/show.html.erb
中創建鏈接。
<%= link_to "Like", like_post_path(@post),
:method => :post, :class => 'btn btn-primary btn-xs' %>
而且在app_contoller方法:
def like
@post = Post.find(params[:id])
current_user.like!(@post)
end
如何寫路線呢?
謝謝。這是作品! –