samedi 15 avril 2017

No matching Route error in Ruby on Rails

I am new in Ruby on Rails. I have been trying for two days to define a route for a method in the controller but error shows saying "No route matches [GET]". Here is the code

donations Controller:

before_action :set_donation, only: [:show, :edit, :update, :destroy, :create_user_account]
  before_action :set_campaign, only: [:new, :create_user_account]
//this is the method that i want to call 
  def create_user_account
  end

Here is my route file

Rails.application.routes.draw do
  resources :donations, except: [:new, :create]
 get 'donations/create_user_account' => 'donations#create_user_account'
  resources :campaigns do
    resources :donations, only: [:new, :create, :create_user_account]
    get 'donations/create_user_account' => 'donations#create_user_account'
  end
  resources :organizations

  devise_for :users

  root to: "campaigns#latest"
end

The routes are showing my route name but when i hit the route "no matching" route error occurs.

route1: campaign_donations_create_user_account_path GET /campaigns/:campaign_id/donations/create_user_account(.:format) donations#create_user_account route2:

donations_create_user_account_path  GET /donations/create_user_account(.:format)    
donations#create_user_account

I want to call route 2 but no route is working

I call my route 2 like this

http://localhost:3000/donations/create_uer_account

This is the error

enter image description here

Aucun commentaire:

Enregistrer un commentaire