在你的else
块中尝试这个:
render html: "".html_safe
请注意,如果要将标记包含在正确的HTML布局中(带有
标记等),则需要明确指定布局:
render( html: "".html_safe, layout: 'application' )
编辑:
这里有一些代码:
应用程序/控制器/ users_controller.rb:
class UsersController < ApplicationController def delete_users users = User.active.where(:id=>params[:users]) array = [] users.each do |user| if user.active? array << user end end if (array.count > 0) user.update_attributes(:status => "inactive") else render( html: "".html_safe, layout: 'application' ) end end end
user.rb:
class User < ActiveRecord::Base # for the sake of example, simply have User.active return no users def self.active none end end
配置/ routes.rb文件:
Rails.application.routes.draw do # simply visit localhost:3000 to hit this action root 'users#delete_users' end