How do I accept an array as an ASP.NET MVC controller action parameter?

The default model binder expects this url: http://localhost:54119/Designs/Multiple?ids=24041&ids=24117 in order to successfully bind to: public ActionResult Multiple(int[] ids) { … } And if you want this to work with comma separated values you could write a custom model binder: public class IntArrayModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var value … Read more

Rails routing to handle multiple domains on single application

It’s actually simpler in Rails 3, as per http://guides.rubyonrails.org/routing.html#advanced-constraints: 1) define a custom constraint class in lib/domain_constraint.rb: class DomainConstraint def initialize(domain) @domains = [domain].flatten end def matches?(request) @domains.include? request.domain end end 2) use the class in your routes with the new block syntax constraints DomainConstraint.new(‘mydomain.com’) do root :to => ‘mydomain#index’ end root :to => ‘main#index’ … Read more

Use anchors with react-router

React Router Hash Link worked for me and is easy to install and implement: $ npm install –save react-router-hash-link In your component.js import it as Link: import { HashLink as Link } from ‘react-router-hash-link’; And instead of using an anchor <a>, use <Link> : <Link to=”home-page#section-three”>Section three</Link> Note: I used HashRouter instead of Router:

React-router v4 – cannot GET *url*

I’m assuming you’re using Webpack. If so, adding a few things to your webpack config should solve the issue. Specifically, output.publicPath=”https://stackoverflow.com/” and devServer.historyApiFallback = true. Here’s an example webpack config below which uses both of ^ and fixes the refresh issue for me. If you’re curious “why”, this will help. var path = require(‘path’); var … Read more

Use specific middleware in Express for all paths except a specific one

I would add checkUser middleware to all my paths, except homepage. app.get(“https://stackoverflow.com/”, routes.index); app.get(‘/account’, checkUser, routes.account); or app.all(‘*’, checkUser); function checkUser(req, res, next) { if ( req.path == “https://stackoverflow.com/”) return next(); //authenticate user next(); } You could extend this to search for the req.path in an array of non-authenticated paths: function checkUser(req, res, next) { … Read more

laravel Unable to prepare route … for serialization. Uses Closure

I think that it’s related with a route Route::get(‘/article/{slug}’, ‘Front@slug’); associated with a particular method in my controller: No, thats not it. The error message is coming from the route:cache command, not sure why clearing the cache calls this automatically. The problem is a route which uses a Closure instead of a controller, which looks … Read more

Passing route control with optional parameter after root in express?

That would work depending on what client.get does when passed undefined as its first parameter. Something like this would be safer: app.get(‘/:key?’, function(req, res, next) { var key = req.params.key; if (!key) { next(); return; } client.get(key, function(err, reply) { if(client.get(reply)) { res.redirect(reply); } else { res.render(‘index’, { link: null }); } }); }); There’s … Read more

Client Routing (using react-router) and Server-Side Routing

Note, this answer covers React Router version 0.13.x – the upcoming version 1.0 looks like it will have significantly different implementation details Server This is a minimal server.js with react-router: var express = require(‘express’) var React = require(‘react’) var Router = require(‘react-router’) var routes = require(‘./routes’) var app = express() // …express config… app.use(function(req, res, … Read more