나는 Recommendable이라는 David Celis 보석을 사용하여 레일 시스템에 비슷한 시스템을 구현하고 있습니다. 콘솔에서 작업 할 수있는 모든 정보를 얻었지만 적절한 경로를 얻을 수없고 "[GET]"/ categories/1/posts/1/like "와 일치하는 경로 없음"오류가 발생합니다 "컨트롤러 동작을위한 경로 추가
나는 내 모델에서 다음과 같은 한 : 내 포스트 컨트롤러에서
class Category < ActiveRecord::Base
has_many :posts, :dependent => :destroy
extend FriendlyId
friendly_id :name, use: :slugged
end
class Post < ActiveRecord::Base
belongs_to :category
end
내가 가진 내 경로에서
class PostsController < ApplicationController
before_filter :authenticate_user!
before_filter :get_category
def like
@post = Post.find(params[:id])
respond_to do |format|
if current_user.like @post
else
flash[:error] = "Something went wrong! Please try again."
redirect_to show_post_path(@category, @post)
end
end
end
end
를 내가 가지고 :
resources :categories do
resources :posts do
put :like, :on => :member
end
end
match 'categories/:category_id/posts/:id', :to => 'posts#show', :as => 'show_post'
누군가 내 오류를 지적 할 수 있습니까? 나는 작동하도록 PUT을 얻을 수 있지만 사용자가 특정 게시물을 좋아할 때 오류가 발생하면 게시물로 리다이렉션하려고 할 때 GET 오류가 어디서 오는지 알 수 없습니다. 미리 감사드립니다.
편집 : 내보기에서
내가 가진 : 당신이 GET
요청을 실행하는 동안
- title "#{@post.class}"
%p#notice= notice
%p
%b Title:
= @post.title
%p
%b Description:
= @post.description
%p
%b Likes:
= @post.liked_by.count
= link_to 'Edit', edit_category_post_path(@post)
\|
= link_to 'Back', category_posts_path
\|
= link_to 'Like', like_category_post_path(@post)
어떻게 당신이 당신의'like' 행동에 도달하려고합니까? 이 링크/버튼을 만들었습니까? 템플릿의 코드를 보여주세요. – jdoe