routes

Rails: Nested resources conflict, how to scope the index action depending on the called route

左心房为你撑大大i 提交于 2019-12-04 17:40:39
问题 Imagine you have two defined routes: map.resources articles map.resources categories, :has_many => :articles both accessible by helpers/paths articles_path # /articles category_articles_path(1) # /category/1/articles if you visit /articles , index action from ArticlesController is executed. if you visit /category/1/articles , index action from ArticlesController is executed too. So, what is the best approach for conditionally selecting only the scoped articles depending on the calling route?

How to convert query string parameters to route in asp.net mvc 4

妖精的绣舞 提交于 2019-12-04 17:36:25
I have a blogging system that I'm building and I can't seem to get ASP.NET MVC to understand my route. the route I need is /blogs/student/firstname-lastname so /blogs/student/john-doe, which routes to a blogs area, student controller's index action, which takes a string name parameter. Here is my route routes.MapRoute( name: "StudentBlogs", url: "blogs/student/{name}", defaults: new { controller = "Student", action="Index"} ); My controller action public ActionResult Index(string name) { string[] nameparts = name.Split(new char[]{'-'}); string firstName = nameparts[0]; string lastName =

No route matches with Nested Resources

荒凉一梦 提交于 2019-12-04 17:10:47
I have two associated tables. Venues and Specials . A venue can have many specials . Once a user has created a venue I wish to allow them to create a special on the venues#index page. By using nested resources I have achieved the desired URL: /venues/5/specials/new . However, my current code results with: No route matches {:controller=>"specials", :format=>nil} I'm guessing the error is with my SpecialsController and the def new and def create functions. I would like the URL to take me to a form page where I can enter new data for the specials <%= link_to 'Add Special', new_venue_special_path

button_to with GET method option in Rails

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:04:11
问题 I have the following button, which I overwrited to generate a GET request: = button_to "Tutor", {:controller => "appointments", :action => "new", :listing_id => @listing.id} , :method => :get However, I still get a POST request with extra params :method: Processing by AppointmentsController#new as HTML Parameters: {"authenticity_token"=>"AWkL", "listing_id"=>"2", "method"=>"get"} I my routes file, I have: resources :appointments What did I do wrong? Thank you. 回答1: Buttons aren't supposed to

How to show all available routes in Spring?

℡╲_俬逩灬. 提交于 2019-12-04 17:02:40
问题 How to show all the routes mapped in a spring based application? In Rails this is done using rake routes. I use two mapping methods of spring to create the URL-mappings: @RequestMapping SimpleUrlHandler I have used the Unix command grep and cut to get all the mappings of @RequestMapping . I wonder if there is some way I can get these details from the Spring application. 回答1: If you set the Log4J category for log4j.logger.org.springframework.web to INFO or DEBUG you should see the list of

Rails route to model instance - by domain name

▼魔方 西西 提交于 2019-12-04 16:44:44
I have a Rails 3 application, say, with hotels, where hotels belong to parent areas. When a user hits the app (served by mongrel >> nginx), I want the domain name used in the request to decide what area of hotels to serve up (domain name >> area). To achieve this I can see two options: 1) Rewrite the URL with nginx, inserting the area id after the domain name (e.g. birminghamhotels.co.uk => proxy_pass http://myupstream/areas/3 $request_uri). Benefits: Domain to object mapping happens where accepted domains are defined: nginx.conf. Should be transparent to users (pretty URLs possible as they

How to dynamically add OData Web Api routes *after* Application_Start?

谁都会走 提交于 2019-12-04 16:36:35
I have an application where I need to add OData routes dynamically. I can add regular routes after Application_Start just fine, but am having trouble doing it with OData routes. Here's how I'm trying to dynamically add OData Web Api routes. In my WebApiConfig, I add a Products route: public static class WebApiConfig { public static void Register(HttpConfiguration config) { var builder = new ODataConventionModelBuilder(); builder.EntitySet<Product>("Products"); config.MapODataServiceRoute(routeName: "ProductsRoute", routePrefix: "odata", model: builder.GetEdmModel()); } } Then in my

Route localization in ASP.NET Core 2

纵饮孤独 提交于 2019-12-04 16:29:45
问题 I am developing an online store using ASP.NET Core 2 and I am struggling with how to implement route localization, ex. depending from the country where user is from I want him to see /en/products or /pl/produkty. I managed to implement culture as part of the url, like /en/...., and user can also change default language by clicking a button on the website. However, I have no idea how to localize whole urls. I don't want to put hundreds of urls in Startup.cs (MapRoute). I need a better solution

Set Yii2 catchAll route depending on database result

佐手、 提交于 2019-12-04 15:24:31
<?php namespace app\modules\site\controllers; use Yii; use yii\filters\AccessControl; use yii\web\Controller; use app\models\SiteSettings; class CommonController extends Controller { public function init() { Yii::$app->language = 'bg-BG'; Yii::$app->formatter->locale = 'bg-BG'; Yii::$app->params['siteSettings'] = SiteSettings::find()->one(); if (Yii::$app->params['siteSettings']->in_maintenance == 1) { Yii:$app->catchAll = ['index/maintenance', 'message' => Yii::$app->params['siteSettings']->maintenance_message]; } } } I tried to set the catchAll route from within the CommonController init

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

偶尔善良 提交于 2019-12-04 15:05:42
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 Found - The page you requested was not found. So my goal is to redirect him to http://www.mywebsite.com