Ruby on rails 找不到操作-路由正确-渲染视图

Ruby on rails 找不到操作-路由正确-渲染视图,ruby-on-rails,controller,action,Ruby On Rails,Controller,Action,我的rails应用程序正在调用一个不存在的方法 我调用的方法的路径是: 获取/获取json(:格式)数据#获取json 我的控制器代码: class DataController < ApplicationController before_filter :authenticate skip_before_filter :verify_authenticity_token protected def authenticate token = params[:toke

我的rails应用程序正在调用一个不存在的方法

我调用的方法的路径是:

获取/获取json(:格式)数据#获取json

我的控制器代码:

class DataController < ApplicationController


 before_filter :authenticate
  skip_before_filter :verify_authenticity_token

protected
  def authenticate
    token = params[:token]
    @user = User.find_by(token: token)
    if @user.nil?
      render nothing: true, status: :unauthorized
      return
    end
  end



  def get_json
    @users = User.all
    @owners = Owner.all
    @tags=Tag.all
    @ideas=Idea.all
    @votes=Vote.all
    @votings=Voting.all
  end
end
下面是我的数据视图(getjson.json.jbuilder):


我们不知道问题出在哪里。

不要在控制器上加保护。 除此之外的一切都受到保护。这就是它找不到动作的原因

像这样:

    class DataController < ApplicationController

     before_filter :authenticate
      skip_before_filter :verify_authenticity_token

     def get_json
        @users = User.all
        @owners = Owner.all
        @tags=Tag.all
        @ideas=Idea.all
        @votes=Vote.all
        @votings=Voting.all
      end

    protected
      def authenticate
        token = params[:token]
        @user = User.find_by(token: token)
        if @user.nil?
          render nothing: true, status: :unauthorized
          return
        end
      end
    end
class-DataController
查看您的路线
数据#getjson
,但控制器中有
get#json
方法,而不是
getjson
。这只是一个输入错误。。我找到了解决办法。关键词:保护我应该写在底部,而不是顶部。这就是为什么rails找不到另一个动作,只是想。。好啊没有行动?但这里的景色如何?让我们只渲染视图…)
    json.tags @tags do |tag|
  json.extract! tag, :id, :typ, :text
end

json.ideas @ideas do |idea|
  json.extract! idea, :id, :title, :text, :owner_id, :voting_id, :voteCount
  json.tags idea.tags do |tag|
    json.extract! tag, :id
  end
end

json.owners @owners do |owner|
  json.extract! owner, :id, :name, :user_id
end

json.votes @votes do |vote|
  json.extract! vote, :id, :kommentar, :owner_id, :voting_id, :idea_id
end

json.votings @votings do |voting|
  json.extract! voting, :id, :status
end

json.users @users do |user|
  json.extract! user, :id, :name, :token, :owner_id, :isLoggedIn
end
    class DataController < ApplicationController

     before_filter :authenticate
      skip_before_filter :verify_authenticity_token

     def get_json
        @users = User.all
        @owners = Owner.all
        @tags=Tag.all
        @ideas=Idea.all
        @votes=Vote.all
        @votings=Voting.all
      end

    protected
      def authenticate
        token = params[:token]
        @user = User.find_by(token: token)
        if @user.nil?
          render nothing: true, status: :unauthorized
          return
        end
      end
    end