Ruby on rails 如何从link_调用操作到

Ruby on rails 如何从link_调用操作到,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,我有索引页用户\u控制器: def index @companies = Company.where(:is_confirmed => "f") respond_to do |format| format.html # show.html.erb format.json { render json: @companies } end end 我想,只要按一下按钮,公司就会将状态更改为“已确认” def confirm

我有索引页用户\u控制器:

  def index
    @companies = Company.where(:is_confirmed => "f")
    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @companies }
    end
  end
我想,只要按一下按钮,公司就会将状态更改为“已确认”

   def confirm
    company = Company.find(params[:id])
    company.is_confirmed = "t"
    company.save
    redirect_to users_path
  end
应该调用确认的按钮

= link_to '<i class="icon-ok icon-white"></i> '.html_safe + t('Confirm'), users_path, confirm: t('Are you sure'), :controller => "users", :action => "confirm", :class => 'btn btn-small btn-success'

请告诉我如何修复或告诉我在哪里可以看到工作版本

您必须在controller/action/id参数和RESTful路由之间进行选择,请检查。你可能想要这个:

= link_to '<i class="icon-ok icon-white"></i> '.html_safe + t('Confirm'), :controller => "users", :action => "confirm", :id => @companies, method: :post, confirm: t('Are you sure'), :class => 'btn btn-small btn-success'

Yuri Barbashov是对的,这里的帖子更有意义。

您必须在controller/action/id参数和RESTful路由之间进行选择,请检查。你可能想要这个:

= link_to '<i class="icon-ok icon-white"></i> '.html_safe + t('Confirm'), :controller => "users", :action => "confirm", :id => @companies, method: :post, confirm: t('Are you sure'), :class => 'btn btn-small btn-success'
= link_to confirm_company_path(company), confirm: 'Are you sure', method: :post do
  %i{class: "icon-ok icon-white"}
  = t('Confirm')
尤里·巴巴肖夫是对的,这里的帖子更有意义

= link_to confirm_company_path(company), confirm: 'Are you sure', method: :post do
  %i{class: "icon-ok icon-white"}
  = t('Confirm')
在routes.rb中

post '/company/:id/confirm' => "users#confirm", as: :confirm_company
1更改对象时不要使用GET请求,而是使用POST

2将确认逻辑移到公司模型,并将确认操作移到公司控制器

在routes.rb中

post '/company/:id/confirm' => "users#confirm", as: :confirm_company
1更改对象时不要使用GET请求,而是使用POST


2将确认逻辑移动到公司模型,并将确认操作移动到公司控制器

您可能需要检查rake路由。您可能需要检查rake路由。非常感谢mechange to=链接到“”。html\u safe+t'confirm',确认公司路径公司,确认:t'You sure',:class=>'btn btn small btn success'和工作感谢您非常帮助mechange将\u链接到“”。html\u safe+t'Confirm',Confirm\u company\u pathcompany,Confirm:t'you sure',:class=>'btn btn small btn success'和工作