2017-06-18 72 views
0

我正在创建一个Rails 4.2.6/MongoDb应用程序。我创建了一个新的动作手动称为“calluser”,取得了路由变化,包括它:在控制器中创建的新操作不起作用

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

我可以看到它时,我执行“耙路线”命令:

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> 
01当我从控制器重定向

任何想法为什么发生这种情况?我会感谢任何帮助。

我读了以前类似的问题,但他们并没有为我工作:

Create a new action for existing controller

Route a form to new controller action in Ruby on Rails

+0

实际路由是在rake路由中显示的路由:'call_user_company'就像你写的“calluser_company”。不知道为什么下划线实际上.. – Maxence

+0

对不起,我粘贴错误的路线:calluser_company GET /companies/:id/calluser(.:format)公司#calluser – user3538384

+0

然后我很努力地看到问题来自哪里。你有没有尝试重新启动服务器?顺便说一句,在JSON中,你重定向到一个不同的动作(显示) – Maxence

回答

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)

+0

我需要添加“_path”作为一个宁静的应用程序。 calluser_company_path – user3538384