Rails 重写 destroy 方法有问题。

jjzxcc · March 05, 2013 · Last by jjzxcc replied at March 06, 2013 · 2614 hits
def destroy
  @message = Message.find(params[:id])
  new_message = Message.find(params[:id])
  new_message[:user_email].slice!(/#{current_user[:email]};*/)
  @message.update_attribute(:user_email, new_message[:user_email])
  if @message[:user_email].empty?
    @message.destroy
  end
  redirect_to messages_path
end

这段代码我单独在 rails c 里面跑可以删除当前的 email。 在程序中只有当前 user_email 为唯一的时候可以删除成功。 当 user_email 的 email 多于 2 个时,无法删除当前 email。 不知道是什么原因,求解。

用 pry 调试一下

正则表达式我还在学,不过我看着正则有点问题。{} 在正则里是语意的。

你这样把 2 个 email 拿出来测试一下看看就行了

rubular.com 你知道吧。复制上去测试一下。很简单。自己能写测试更好。很容易找出来。

我自己试了一下原来这样是可以的#{}.

@guyanbiao 调试过啦。在命令行是成功的,但通过页面就不行,很郁闷。

You need to Sign in before reply, if you don't have an account, please Sign up first.