没有路线匹配[POST]“/ profile_settings”

时间:2015-08-19 19:33:11

标签: ruby-on-rails post controller routes

我有以下表格谁应该更新用户,但我一直得到这个没有路由匹配[POST]“/ profile_settings”消息,一切似乎都正确所以我不知道为什么

= form_for update_user_profile_setting_path(current_user.id), method: :post do |f|
    .profile_form
      %br
        = f.text_field :name, placeholder: 'Name',class: 'default-input text_field'
      %br
        = f.text_field :email, placeholder: 'Email', class: 'default-input text_field', id: 'email_profile'
      %br
        = f.text_field :address, placeholder: 'Address', class: 'default-input text_field'
      %br
        = f.password_field :password, placeholder: 'Password', class: 'default-input text_field black-font'
      %br
        = f.password_field :password_confirmation, placeholder: 'Password Confirmation', class: 'default-input text_field black-font'
      %br
        = f.file_field :avatar, placeholder: 'Avatar', class: 'default-input'
      .actions 
        = f.submit "Update Settings", class: 'btn btn-success default-input'

控制器方法

def update_user
respond_to do |format|
  if @user.update(user_params)
    format.html { redirect_to @user, notice: 'User was successfully updated.' }
    format.json { head :no_content }
  else
    format.html { render action: 'edit' }
    format.json { render json: @user.errors, status: :unprocessable_entity }
  end
end
end

路由

resources :profile_settings, :only => [:index] do
  post :update_user, on: :member
end

我可能会遗漏一些东西,但我真的不知道是什么...... 任何帮助将不胜感激

3 个答案:

答案 0 :(得分:1)

提交后,您的表单会查找{ "current":1, "rowCount":10, "rows":[ {"CustomerID":"88888888-8888-8888-8888-888888888888","JobNumber":"DMPC-2","JobName":"DMPC-2: Transfer 645 Units to Warehouse","JobState":"Request Draft","JobStatus":"In Planning","JobRequestor":"Jim Halpert","LastModifiedUTS":1439768413,"LastModifiedDate":"8/16/2015"}, {"CustomerID":"88888888-8888-8888-8888-888888888888","JobNumber":"DMPC-1","JobName":"DMPC-1: Scranton Chamber of Commerce Delivery","JobState":"Request Draft","JobStatus":"Pending Approval","JobRequestor":"Dwight Schrute","LastModifiedUTS":1440009361,"LastModifiedDate":"8/19/2015"} ], "total":2 } 方法。

要尊重update约定,请将CRUD重命名为update_user。然后,在update中,将您使用的代码替换为routesresources :profile_settings, :only => [:index, :update]

答案 1 :(得分:0)

您的表单需要遵循以下路线

/profile_settings/:user_id/edit

还将表单标记设置为= form_for(@user) do |f|

然后它应该自动使用update控制器方法。

答案 2 :(得分:0)

var dto = new DataObject(); dto.SetText(richTextBox.SelectedRtf, TextDataFormat.Rtf); //Since notepad sux and doesn't understand \n, //we need to fix it replacing by Environment.NewLine (\r\n) string unformattedText = richTextBox.SelectedText.Replace("\n", Environment.NewLine); dto.SetText(unformattedText, TextDataFormat.UnicodeText); Clipboard.Clear(); Clipboard.SetDataObject(dto); 需要UpdatePatch。您需要更改Putroutes

form

并改变

resources :profile_settings, :only => [:index] do
  patch :update_user, on: :member
end

= form_for update_user_profile_setting_path(current_user.id), method: :post do