0

I have internal messages in my application. I am using devise and I have installed password module but did not configured it yet. when I tried to press on Forget Password? I got this error:

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

So what I need is: How to solve this problem ? and How to make the forget password feature works for action mailer so user can reset his password using the email which saved in the database.

Note: Before installing internal messages into my app , when i tried to click forget password link it was redirecting normally.

I am using another controller for registration instead of that one by devise and on signup , users are added by admin. this is from my routes file

  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

Forget Password link

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

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

Users_Controller.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

Messaages_controller.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
Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61
  • I cannot see any routes code for your messages controller......so how can you expect that route? – Rajarshi Das Sep 20 '13 at 05:19
  • what do you mean ?, i have internal inbox between users and its working and before adding this feature the link of forget password was redirecting normally – Mostafa Hussein Sep 20 '13 at 05:33
  • can you please post your routes.rb ? ..... – Rajarshi Das Sep 20 '13 at 05:35
  • look at your routes is there anything `inbox` over there ...can you please post your forgot password link code? – Rajarshi Das Sep 20 '13 at 05:46
  • forget password link added , and the inbox is my internal messages. do you want me to post messages controller ? – Mostafa Hussein Sep 20 '13 at 05:54
  • @RajarshiDas any new ? – Mostafa Hussein Sep 20 '13 at 08:05
  • wait a minute...there is a mistake i think it is not a valid routes please do `rake routes` in console check whether it is exists or not .... https://github.com/ryanb/railscasts-episodes/tree/master/episode-209/ – Rajarshi Das Sep 20 '13 at 08:06
  • its exist , i told you the link was working before i have internal messages in my application – Mostafa Hussein Sep 20 '13 at 08:18
  • actually there is lot of issues/mess on your code please post your messages and user controller `resources :users, only: [:index, :new, :create, :show, :destroy, :edit, :update]` why it is required ? – Rajarshi Das Sep 20 '13 at 08:19
  • `resources :users, only: [:index, :new, :create, :show, :destroy, :edit, :update]` to override registration controller by user controller – Mostafa Hussein Sep 20 '13 at 08:23
  • there is a lot of mess in your codes ...please read devise first....you make STI from Application contoller why ? what the need of then devise?....Please read devise http://railscasts.com/episodes/209-introducing-devise and customization http://stackoverflow.com/questions/5851801/how-do-i-customize-the-controller-for-registration-in-devise – Rajarshi Das Sep 20 '13 at 08:27
  • there is no sign up in my application so i don't need the registration module so i removed it – Mostafa Hussein Sep 20 '13 at 08:29
  • my problem is not about the rigestration module , forget password is working with password controller , but i don't know its conflicting with messages controller – Mostafa Hussein Sep 20 '13 at 08:33

1 Answers1

0

Since it's showing user_id => nil. Can you check if your session is not expired

Mandeep
  • 9,093
  • 2
  • 26
  • 36