在控制器中创建的新操作无效

时间:2017-06-18 22:55:02

标签: ruby-on-rails mongodb routes

我正在创建一个Rails 4.2.6 / MongoDb应用。我手动创建了一个名为“calluser”的新动作,对路径进行了更改以包含它:

  resources :companies do
    member do
      get 'calluser'
    end
  end

当我执行'rake routes'命令时,我可以看到它:

call_user_company GET  /companies/:id/call_user(.:format)   companies#call_user

但是,当我从控制器重定向时:

  if @company.save
    format.html { redirect_to calluser_company(@company), notice: 'Company was successfully created.' }
    format.json { render action: 'show', status: :created, location: @company }
  else
    format.html { render action: 'new' }
    format.json { render json: @company.errors, status: :unprocessable_entity }
  end

我收到以下错误:

undefined method `calluser_company' for #<CompaniesController:0x007fdd893f3270>

任何想法为什么会这样?我将不胜感激。

我读过以前类似的问题,但它们对我不起作用:

Create a new action for existing controller

Route a form to new controller action in Ruby on Rails

1 个答案:

答案 0 :(得分:0)

您的路线描述:

call_user_company GET /companies/:id/call_user(.:format) companies#call_user

因此您可以使用call_user_company_url(@company)call_user_company_path(@company)代替calluser_company(@company)

相关问题