routes

Devise & Custom Rails User URLs

纵然是瞬间 提交于 2019-12-22 12:26:10
问题 I am currently using Rails 3.2.5 with the latest devise gem. Currently users can access their profile page at... example.com/users/john-doe I want to remove the users portion of the url, so the url would be example.com/john-doe . Is this possible with devise? Right now in my routes file I have the following... devise_for :users, :controllers => {:omniauth_callbacks => 'omniauth_callbacks'} 回答1: Just add a route for it. You will probably want it to be the last one in the routes file. Something

laravel 5 return HTML or JSON depending on route

a 夏天 提交于 2019-12-22 11:30:53
问题 I want to show different output - JSON or HTML. I cannot use the \Request::ajax() feature as I just get normal request (JSON response is not based on XHR-Requests). Is there perhaps a possibility to distinguish the output by different routes? E.g. check if the controller is called by a route with the prefix "mob" and then create a switch for the output based on that? app/Http/routes.php: Route::group( ['prefix' => 'api'], function( ) { Route::resource( 'activation', 'ActivationController' );

flask-restful having a get/<id> and post with json in the same class

一曲冷凌霜 提交于 2019-12-22 10:27:04
问题 The get method on user works if the # api.add_resource(User, '/user/') line is uncommented, and the other api.add_resource is. The inverse of that is true to make the post method work. How can I get both of these paths to work? from flask import Flask, request from flask.ext.restful import reqparse, abort, Api, Resource import os # set the project root directory as the static folder, you can set others. app = Flask(__name__) api = Api(app) class User(Resource): def get(self, userid): print

rails, adding a parameter to new route

我怕爱的太早我们不能终老 提交于 2019-12-22 10:06:32
问题 The new action normally doesn't require parameters, since it creates a new resource from scratch. In my application whenever i create a certain type of resource say a book i need to provide a template, that is the id of another book . So my new route always has a parameter. I don't know how to represent this fact into routes.rb file. Since i don't even know whether it is feasible, just in the case it isn't, then i will create a new_wp, a "new with parameter" action. I tried to add it to my

Angular 2 Resolve Root Component before instantiating child components

只谈情不闲聊 提交于 2019-12-22 09:39:51
问题 When I refresh my web-app, I want it to request the potential signed in user's data before instantiating any components or routes. If the user's data was found, I want to inject it into a service, which all my other sub components depend on. Scenario: Say I have 3 components, App (ROOT), Home & About. If I place this code in my About component, I expect it to wait 20seconds before it instantiate, instead, the component gets instantiated instantly, only when I move away from this component, it

Google API (directions) - creating routes that avoid certain points [duplicate]

人走茶凉 提交于 2019-12-22 08:54:53
问题 This question already has answers here : Blacklisting specific roads from Google Maps/Mapquest? (4 answers) Closed 2 years ago . Google Maps API does not seem to provide a means to create routes that avoid or tend to avoid certain points. Has anyone worked on something like this? I want to create exception rules on routes. For example: show routes that do not have traffic signals. 回答1: I had the same problem and this is by far the best solution i have found. "As mentioned in another answer,

Mobile version of site using CodeIgniter

倾然丶 夕夏残阳落幕 提交于 2019-12-22 08:31:13
问题 What I want to do is to create a mobile version of my web site in CodeIgniter. I want to redirect my complete web site to m.example.com There will be no change in controllers, neither in views and models. Both will be the same. I don't want to change my .htaccess file. Any possible solutions for this? 回答1: The user agent class has a function; $this->agent->is_mobile(); You could use this in the construct of your base controller(s) to test if mobile. 回答2: Instead of rewriting your code all

webapp2 Route to match all other paths

╄→尐↘猪︶ㄣ 提交于 2019-12-22 08:27:22
问题 I've the following code in my main app. I expect all paths other than the first two to be caught by the last route (/.*). But I get 404 error. What am I missing? import webapp2 from webapp2 import WSGIApplication, Route # ---- main handler class MainPage(webapp2.RequestHandler): def get(self): ret = jinja2render.DoRender(self) return ret routes = [ Route (r'/rpc', handler = 'rpc.RPCHandler'), Route (r'/secured/somesecuredpage', handler = 'secured.securedPageHandler'), Route (r'/.*', handler =

How do you use ActionDispatch::Routing::RouteSet recognize_path?

拜拜、爱过 提交于 2019-12-22 08:01:34
问题 How do you use ActionDispatch::Routing::RouteSet recognize_path? I want to get the current path for the view. I tried <div id="<%= ActionDispatch::Routing::RouteSet::recognize_path %>"> but got "undefined method `recognize_path' for ActionDispatch::Routing::RouteSet:Class". Thanks! 回答1: Path of the Request: request.path Path of the file: __FILE__ 回答2: You can do this Rails.application.routes.recognize_path "/your/path" It works in rails 3.1.0.rc4 来源: https://stackoverflow.com/questions

ASP.NET MVC 2 RC 2 returns Area-specific controller when no area specified

家住魔仙堡 提交于 2019-12-22 07:37:06
问题 I have a basic MVC 2 (RC2) site with one base-level controller ("Home"), and one area ("Admin") with one controller ("Abstract"). When i call http://website/Abstract - the Abstract controller in the Admin area gets called even though i haven't specified the Area in the URL. To make matters worse - it doesn't seem to know it's under Admin because it can't find the associated view and just returns: The view 'Index' or its master was not found. The following locations were searched: ~/Views