简体   繁体   中英

Why am I getting Template not found

I have the following routes:

create_admin_path   GET     /app/views/createAdmin/create_admin.html.erb(.:format)  application#createAdmin

I have this in routes.rb

get "/app/views/createAdmin/create_admin.html.erb", to: "application#createAdmin", as: "create_admin"

I have this in the application_controller.rb

def createAdmin

end 

and in the view I have a folder called createAdmin which has a file called create_admin.html.erb

in the create_admin.html.erb I have something like this:

<h1> testing is here </h1>  

Yet I am receiving this error message:

No route matches [GET] "/app/views/create_admin/create_admin.html.erb"

What am I doing wrong ?

Thanks for your time

The views must match in controller name and view file name, that's if you're registering the route to application#createAdmin , then the folder must be application/ and the file createAdmin , in camel case as you've named the action and the route, so your file must be called createAdmin and must be located in a folder called application/ .

/app/views/application/createAdmin.html.erb.

But, there are some things to add:

There's no need to use the ApplicationController to handle such operations, you can easily create a new controller and use it with that purpose instead polluting the ApplicationController.

You don't need to specify the full route to the view as the URI when registering a route, unless it's that specifically what want to do.

When working with Ruby use snake case .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM