1

Socialization gemを使い始めました。したがって、devise を使用して User モデルを作成しました。

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

次に、足場を使用して Post を作成しました。

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

このルートの書き方は?

4

1 に答える 1