dev
dev

Reputation: 127

No route match even when route is defined

I have just started working in rails. I have a controller that redirects to another controller to send an email for emailid verification.

def create
  @user = User.new(user_params)
  respond_to do |format|
    if @user.save

      redirect_to :controller => 'verify', :action => 'sendmail'
    else
      format.html { render :new }

    end

and this is the route in routes file resources :verify but still the program is returning an error No route matches {:action=>"sendmail", :controller=>"verify"}

This is the code of the controller to which I am redirecting

def sendmail
    # type = 1 for email and 2 for reseting password

    randomNumber=rand()
    verification[:value]=BCrypt::Password.create(randomNumber, :cost => 1)
    verification[:type] = 1
    if verification.save
    Usermail.registered(@verification).deliver
end

Upvotes: 1

Views: 179

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42799

I think Verify (singular) as a controller name won't easily be mapped by resources, instead just add a custom match

get '/verify/sendmail', to: 'verify#sendmail', as: :verification_mail

Then do

redirect_to verification_mail_path

Upvotes: 2

Related Questions