0

我的应用程序中有内部消息。我正在使用设计并且我已经安装了密码模块但尚未配置它。当我试图按下忘记密码?我收到了这个错误:

 No route matches {:controller=>"messages", :mailbox=>:inbox, :user_id=>nil}

所以我需要的是:如何解决这个问题?以及如何使忘记密码功能适用于操作邮件,以便用户可以使用保存在数据库中的电子邮件重置他的密码。

注意:在将内部消息安装到我的应用程序之前,当我尝试单击忘记密码链接时,它会正常重定向。

我正在使用另一个控制器进行注册,而不是通过设计和注册,用户由管理员添加。这是来自我的路线文件

  devise_for :users, :controllers => { :registrations => "users" }
  resources :users, only: [:index, :new, :create, :show, :destroy, :edit, :update] do |user|
    resources :messages do
      collection do
        post 'delete_multiple'
      end
    end
  end

忘记密码链接

<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>

 <%= link_to "Forgot your password?", new_password_path(resource_name), :class => "btn btn-danger" %><br />
<% end -%>

用户控制器.rb

class UsersController < ApplicationController
  load_and_authorize_resource
  def index
    @users = User.all
    @users_grid = initialize_grid(User,
      :per_page => 5)
  end

  def show
    @user = User.find(params[:id])

  end


  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      flash[:notice] = 'A new user created successfully.'
      redirect_to users_path
    else
      flash[:error] = 'An error occurred please try again!'
      redirect_to users_path
    end
  end

  def edit
    @user = User.find(params[:id])
  end

  def update
    @user = User.find(params[:id])
    if @user.update_attributes(params[:user])
      flash[:notice] = 'Profile updated'
      redirect_to users_path
    else
      render 'edit'
    end
  end

  def destroy
    @user = User.find(params[:id])
    if current_user == (@user)
      flash[:error] = "Admin suicide warning: Can't delete yourself."
    else
      @user.destroy
      flash[:notice] = 'User deleted'
      redirect_to users_path
    end
  end
end

消息控制器.rb

class MessagesController < ApplicationController
    before_filter :set_user

  def index
    if params[:mailbox] == "sent"
      @messages = @user.sent_messages
    elsif params[:mailbox] == "inbox"
      @messages = @user.received_messages
    #elsif params[:mailbox] == "archieved"
     # @messages = @user.archived_messages
    end
  end

  def new
  @message = Message.new
  if params[:reply_to]
      @reply_to = User.find_by_id(params[:reply_to])
      unless @reply_to.nil?
        @message.recepient_id = @reply_to.id
      end
    end
  end

  def create
    @message = Message.new(params[:message])
    @message.sender_id = @user.id
    if @message.save
      flash[:notice] = "Message has been sent"
      redirect_to user_messages_path(current_user, :mailbox=>:inbox)
    else
      render :action => :new
    end
  end

  def show
    @message = Message.readingmessage(params[:id],@user.id)
  end

  def delete_multiple
    if params[:delete]
      params[:delete].each { |id|
        @message = Message.find(id)
        @message.mark_message_deleted(@message.id,@user.id) unless @message.nil?
      }
      flash[:notice] = "Messages deleted"
    end
    redirect_to user_messages_path(@user, @messages)
  end

  private
  def set_user
    @user = current_user
  end
end
4

1 回答 1

0

因为它显示 user_id => nil。你能检查一下你的会话是否没有过期吗

于 2013-09-20T05:15:33.083 回答