Laravel 5 - Resource Controller in Subfolder - restful-architecture

Take a look at this folder structure:
Controllers
-> User
- UserController.php
And this is what i got in my routes.php:
Route::resource('user', 'User\UserController');
What am I doing wrong? I got a 404 error.

If you have your controllers nested try to use underscores instead of backslashes, try this
Route::resource('user', 'User_UserController');

Related

How do you use a Controller within a blade/error.php file?

When I try App::make('App\Http\Controllers\HomeController') I just get server error 500 (and nothing else more helpful)
So now it's just app('App\Http\Controllers\HomeController');
But for most pages I can pass $this into the view from the controller to have access to it on the view

nuxtjs route map in order

I have an issues with nuxtjs route naming.
Ex: my pages folder is
page:
-|blog:
-|_categorySlug.vue
-|_postSlug.html.vue
-|service:
-|index.vue
When i access url like
example.com/blog/demo-post-slug.html -> route map to /blog/_categorySlug.vue
example.com/blog/demo-category-slug -> route map to /blog/_categorySlug.vue
Because _categorySlug.vue place in the first order inside dir blog.
When i change the file name _postSlug.html.vue to _aPostSlug.html.vue to make it become the first order.
page:
-|blog:
-|_aPostSlug.html.vue
-|_categorySlug.vue
-|service:
-|index.vue
It's all right but the file naming isn't good. Anyone can give me an suggestion for this?
Thanks!

Rails 3 Routes - prepend all url paths with set string

I've been asked to change the routes on a Rails project such that the routes will only respond to requests where the app name (or other arbitrary string) is the first string after the domain name, e.g.
www.thething.com/appname/users/sign_in instead of www.thething.com/users/sign_in
www.thething.com/appname instead of www.thething.com
www.thething.com/appname/search instead of www.thething.com/search
I've suggested using a subdomain appname.thething.com instead, but the client is quite specific about wanting the URL in the above format.
www.thething.com will be a splash page which will contain a link to www.thething.com/appname, with the intention of adding additional apps/pages in future with new folder names.
Is there an easy way of modifying the routes file so that all routes will get the .../appname prepended to all resources and routes, while being after the domain?
One option is wrap all existing routes in: namespace :appname do ... end, like so:
# config/routes.rb
Appname::Application.routes.draw do
namespace :appname do
# existing routes go here
end
end
I'm not sure if this is the most elegant solution, but it will prepend /appname to all the routes.

tradeoff routes and views rails 3

here it's routes.db
resources :licenses do
resources :sublicenses do
resources :time_licenses
end
end
Then there is a client application that calls time_licenses_controller for creating new time_licenses, the controller responds with a json file, but i don't need to show any view.
Somewhere else instead i need to show to the client an index file including all time_licenses for every sublicense.
That's the path
license/:id/sublilicense/:id/time_lincenses
Now i have a problem with the routes. When i call the create on time_licenses_controller i get this error:
No route matches "/time_licenses.js"
that i can solve changing the routes.db file like this
resources :time_licenses
resources :licenses do
resources :sublicenses
end
but in that case i get the same error linking the index view.
What do you suggest me? Do i have to create two different controllers?
Since you are using nested resources, you will always need to specify license and sublicense while specifying the path to timelicense.
Your path helpers will be:
license_sublicense_timelicense_path(#license, #sublicense, #timelicense) and so on
You can get the path names for the timelicense by
rake routes
Refer rails guides - nested resources for any doubts.

Missing routes in rails after using resource keyword

Not sure what the issue is here, but I have a basic line in my routes.rb:
resource :videos
But I don't see all the paths. Namely:
GET /videos/:id
I only see the following when running "rake routes":
videos POST /videos(.:format) videos#create
new_videos GET /videos/new(.:format) videos#new
edit_videos GET /videos/edit(.:format) videos#edit
GET /videos(.:format) videos#show
PUT /videos(.:format) videos#update
DELETE /videos(.:format) videos#destroy
What am I missing? Thanks!
You make videos a singular resource, but videos is a collection so you have to do :
resources :videos
http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions
Change your line to resources :videos, and the missing route will magically appear