Ajax request causing “param is missing or the value is empty” error

我怕爱的太早我们不能终老 提交于 2019-12-06 01:11:17

You should really let Rails handle your AJAX requests for you. I'd pull that button outside of the form that's being submitted and put it into its own link_to or button_to, just add method: :get if you want to use a button. Set remote: true and it will handle all the AJAX work for you.

<%= link_to 'Get Config', get_config_projects_url(@project.id, project: { unit_mgt_address: @project.UnitMgtAddress }), remote: true %>

or

<%= button_to 'Get Config', get_config_projects_url(@project.id, project: { unit_mgt_address: @project.UnitMgtAddress }), remote: true, method: :get %>

Syntax might need to be tweaked slightly, for your path in particular, but letting Rails manage this sort of thing is a lot cleaner than what you're trying to do. Read up on the syntax for button_to here.

For anyone viewing this many years later. I think you needed to put a "project" object param under your data to encompass your intended params. For anyone else it's the object name (:page, :person etc)

Rails expects this in its controllers.

so;

data: {
  project: {
    id: <%= @attero.id %>,
    unit_mgt_address: $('.unit_mgt_address_class').val()
  }    
}
Raymond Liu

Will this work?

data: {
    "id": <%= @project.id %>,
    "project[UnitMgtAddress]": $('.unit_mgt_address_class').val(),
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!