Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 通过应用程序访问资源有很多直通和路径帮助器_Ruby On Rails_Activerecord_Has Many Through - Fatal编程技术网

Ruby on rails 通过应用程序访问资源有很多直通和路径帮助器

Ruby on rails 通过应用程序访问资源有很多直通和路径帮助器,ruby-on-rails,activerecord,has-many-through,Ruby On Rails,Activerecord,Has Many Through,我有一个应用程序,用户可以在其中跟踪律师事务所 我有三种型号 -使用者 -坚定的 -跟随 最简单的方法是在FirmsController上执行follow操作 在config/routes.rb中: resources :firms do post :follow, on: :member end resources :firms do resource :follow, on: :member end 在固件控制器中: def follow @firm.users <&l

我有一个应用程序,用户可以在其中跟踪律师事务所

我有三种型号 -使用者 -坚定的 -跟随


最简单的方法是在
FirmsController
上执行
follow
操作

config/routes.rb
中:

resources :firms do
  post :follow, on: :member
end
resources :firms do
  resource :follow, on: :member
end
固件控制器中

def follow
  @firm.users << current_user
end
您将创建一个如下控制器:

class FollowsController < ApplicationController
  def create
    @firm = Firm.find params[:firm_id]
    @firm.users << current_user
    # respond with success
  end

  def destroy
    @firm = Firm.find params[:firm_id]
    @firm.users.delete current_user
    # respond with success
  end
end
class FollowsController@公司用户你好,查理,谢谢你帮我一把!我已经尝试过这两种方法,在这两种情况下,rails似乎都是通过follow方法将其玩具扔出婴儿车。没有路径匹配{:action=>“follow”,:controller=>“firms”}如果我解决了它,我会让你知道!当我输入rake routes follow_firm POST/firms/:id/follow(:format)firms#follow时,会出现这种情况。我应该如何在firms controller中定义follow方法?也许这就是我的问题?
def follow
  @firm.users << current_user
end
<%= link_to "Follow", follow_firm_path(@firm), method: :post %>
resources :firms do
  resource :follow, on: :member
end
class FollowsController < ApplicationController
  def create
    @firm = Firm.find params[:firm_id]
    @firm.users << current_user
    # respond with success
  end

  def destroy
    @firm = Firm.find params[:firm_id]
    @firm.users.delete current_user
    # respond with success
  end
end