routes

No route matches [GET] “/logout” [rails]

跟風遠走 提交于 2020-01-14 13:03:52
问题 I get the following routing error when I click on "logout": No route matches [GET] "/logout" This is my application.html.erb file: <% if session[:user_id] %> <%= link_to 'Logout', logout_path, :method => :delete %> <% end %> This is my routes.rb file: get 'admin' => 'admin#index' controller :sessions do get 'login' => :new post 'login'=> :create delete 'logout' => :destroy end get "sessions/create" get "sessions/destroy" Does anybody know how to solve this problem? 回答1: Have you enabled the

Route to controller in subfolder not working in Laravel 4

我是研究僧i 提交于 2020-01-13 08:49:26
问题 I was updating my Laravel 3 app to Laravel 4 when I hit this problem... Routes I have tried: Route::get('backend/login', 'backend/UserController@login'); Route::get('backend/login', 'backend.UserController@login'); 回答1: I had a similar issue just a few hours ago and had to play a little bit with it to have it working. Routes: Route::group(array('prefix' => 'admin'), function() { Route::resource('/', 'admin\DashboardController'); }); In "controllers/admin" i put the DashboardController:

Route to redirect to a controller + an action by default on CodeIgniter?

南楼画角 提交于 2020-01-13 05:39:07
问题 I'm currently working on a project with Codeigniter. I have one controller called Cat class Cat extends CI_Controller { function __construct(){ parent::__construct(); } function index($action){ // code here } } and a route (in routes.php) $route['cats/:any'] = 'cat/index/$1'; And that works if I use this URL for example: http://www.mywebsite.com/cats/display Nevertheless, if the user changes the URL to http://www.mywebsite.com/cats/ it doesn't work anymore. Codeigniter writes: 404 Page Not

ZF2 route parameters with slash

被刻印的时光 ゝ 提交于 2020-01-13 04:23:28
问题 Is it possible to assemble a route with parameters containing forward slashes? Config: 'someroute' => array( 'type' => 'Zend\Mvc\Router\Http\Segment', 'options' => array( 'route' => 'someroute/:path', 'defaults' => array( 'controller' => 'Controller', 'action' => 'index' ), 'constraints' => array( 'path' => '(.)+' ) ) ) Controller: $path = 'some/subdirectory'; $this->url('someroute', array('path' => $path)); Results in: http://host.name/someroute/some%2Fsubdirectory 回答1: Using rawurldecode()

Using resources with custom controller names

℡╲_俬逩灬. 提交于 2020-01-12 13:46:33
问题 I'm using nested resources, however i come across controller names that should be more descriptive. For instance i have a controller ProductsController and ImagesController resources :products do resources :images end This works fine, but later i might need to use the ImageController for other than products images, therefore it should be named ProductsImagesController . But how can i specify the controller name on resources() without falling back to something ugly like: match 'products/images

Using resources with custom controller names

杀马特。学长 韩版系。学妹 提交于 2020-01-12 13:45:32
问题 I'm using nested resources, however i come across controller names that should be more descriptive. For instance i have a controller ProductsController and ImagesController resources :products do resources :images end This works fine, but later i might need to use the ImageController for other than products images, therefore it should be named ProductsImagesController . But how can i specify the controller name on resources() without falling back to something ugly like: match 'products/images

MVC Dynamic Routes

妖精的绣舞 提交于 2020-01-12 10:19:07
问题 I would like to create dynamic urls that route to controller actions with an Id value. I've created the following route using a catch-all parameter routes.MapRoute( "RouteName", "{id}/{*Url}", new { controller = "Controller", action = "Action", id = "" } ); This works as expected and allows me to use the following Urls: "http://website.com/1/fake/url/path" (1 being the id that gets passed to the action method) Does anyone know a way to achieve it this way instead without creating my own http

MVC Dynamic Routes

半世苍凉 提交于 2020-01-12 10:19:04
问题 I would like to create dynamic urls that route to controller actions with an Id value. I've created the following route using a catch-all parameter routes.MapRoute( "RouteName", "{id}/{*Url}", new { controller = "Controller", action = "Action", id = "" } ); This works as expected and allows me to use the following Urls: "http://website.com/1/fake/url/path" (1 being the id that gets passed to the action method) Does anyone know a way to achieve it this way instead without creating my own http

How to override routes path helper in rails?

喜夏-厌秋 提交于 2020-01-12 09:04:24
问题 My route is defined like this match '/user/:id' => 'user#show', :as => :user If for some reason a nil ID is passed I want the route helper to return only '#' and if ID is not nil i want it to return normal path like '/user/123'. or is there any better way to do it. this route helper has been used in lot of places in my code so I dont want to change that. Instead I am looking for one place which will effect all instances of user_path. Thanks 回答1: module CustomUrlHelper def user_path(user,

How to override routes path helper in rails?

扶醉桌前 提交于 2020-01-12 09:02:25
问题 My route is defined like this match '/user/:id' => 'user#show', :as => :user If for some reason a nil ID is passed I want the route helper to return only '#' and if ID is not nil i want it to return normal path like '/user/123'. or is there any better way to do it. this route helper has been used in lot of places in my code so I dont want to change that. Instead I am looking for one place which will effect all instances of user_path. Thanks 回答1: module CustomUrlHelper def user_path(user,