查看:
<%= button_to 'Delete Friend', friendships_path(:friend_id => @user), method: 'delete', :form_class => 'delete_btn', remote: true %>
控制器:
def destroy
@return = 'It works!'
render :json => ActiveSupport::JSON.encode( @return )
end
当我点击按钮时,我得到 404页面未找到 ...如何使销毁方法为 ajax jquery请求 >
编辑:
的routes.rb
resources :friendships, :except => [:new, :edit, :update, :index, :show]
正在运行rake:routes
friendships POST /friendships(.:format) friendships#create
friendship DELETE /friendships/:id(.:format) friendships#destroy
答案 0 :(得分:2)
替换:
friendships_path(:friend_id => @user)
使用:
friendship_path(:id => @user)