1

我有索引页 users_controller:

  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'

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

4

2 回答 2

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

在路线.rb

post '/company/:id/confirm' => "users#confirm", as: :confirm_company

GET1)更改对象时不要使用请求,POST而是使用。

2) 将确认逻辑移至公司模型并确认动作至公司控制器

于 2012-10-15T13:12:50.360 回答
1

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

= 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 '<i class="icon-ok icon-white"></i> '.html_safe + t('Confirm'), confirm_users_path(@companies), method: :post, confirm: t('Are you sure'), :class => 'btn btn-small btn-success'

暗示你的路线看起来像这样(RESTful):

resources :users do
  post 'confirm'
end

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

于 2012-10-15T13:01:22.003 回答