Rails:link_to出错:method =>帖子正在抛出错误

时间:2015-05-02 07:11:29

标签: ruby-on-rails ruby-on-rails-4

我们的erb视图包含以下代码 -

<h1><%=@subreddit.title.capitalize%> Posts</h1>

<%= link_to 'New Post', new_user_post_path(current_user)  if current_user  %>
<div id="<%= @subreddit.id  %>">
<span> Total subscribers:</span> 
<span class="subscriber_co![unt"><%=@subscriber_count%></span><br>
<%= link_to('Subscribe', subscribers_path,:remote => true, :class => 'subscribed ', :method => post)%>
</div>][1]
<br><br>

然而,这会引发以下错误:

http://i.stack.imgur.com/ni3Tb.png

相应的控制器代码 -

class PostsController < ApplicationController
  before_filter :authorize
  def index
  end

  def new
  end

  def show
    cids = Comment.all.map { |c| c.id}
    @vote_count_arr = cids.map { |cid| CommentVote.where(comment_id: cid).inject(0) {|sum,cv| sum+cv.vote_val}}
    @post = Post.find(params[:id])
    @comment = Comment.where(post_id: params[:id])
  end

  private
  def post_params
    params.require(:post).permit(:title, :content, :subreddit)
  end
end

为简洁起见,我排除了大部分控制器代码。请让我知道如何解决错误。

1 个答案:

答案 0 :(得分:1)

您在:之前忘记了post,因此它正在搜索变量或方法post而不是符号:post

<%= link_to('Subscribe', subscribers_path,:remote => true, class: 'subscribed ', method: :post)%>