routes

Rails, Devise: Same resource, different controller based on user type

邮差的信 提交于 2019-12-08 01:33:04
问题 I have a resource, say Product , which can be accessed by two different user classes: say Customer and Admin . There is no inheritance between these two. I am using Devise for authentication: # config/routes.rb devises_for :customers deviser_for :admins I have these two controllers: # app/controllers/customers/products_controller.rb class Customers::ProductsController < ApplicationController and # app/controllers/admins/products_controller.rb class Admins::ProductsController <

Rspec namespaced route specs failing even though route exists

可紊 提交于 2019-12-08 01:29:57
问题 I'm using rspec-rails (2.8.1) and rails 3.1.3 . I'm trying to test routes for my Admin::ZonesController. I have verified the route exists in both the browser and by running rake routes . I am not using ActiveRecord (if that matters). When I run the routing spec, it tells me: ActionController::RoutingError: No route matches "/admin/zones/new" Here is the test (spec/routing/admin/zones_routing_spec.rb): require 'spec_helper' describe "routing to zones" do it "routes /admin/zones/new to admin

Rails access request in routes.rb for dynamic routes

非 Y 不嫁゛ 提交于 2019-12-08 01:28:21
问题 Our websites should allow to show different contents related to the given url .. something like a multisite in wordpress where we have one installation and serve the content according to the url. as it is necessary to have the routes in the correct language I want to use a "dynamic route" approach to serve the right content. My problem is now that I dont find a way how to serve the proper routes in routes.rb if they are dynamic. How can I "access" or "pass" the request object into any method

Routes with multiple, optional, and pretty parameters

一个人想着一个人 提交于 2019-12-08 01:22:31
问题 I have a situation where I'm in need to constructing pretty url paths. I have a FilesController that need to handle URLs like: mydomain.com/files/path/dir1/dir2/user/bob mydomain.com/files/path/dir1/user/bob mydomain.com/files/path/dir1 mydomain.com/files/user/bob In the controller, I want params[:path] to contain everything between /path and /user and params[:user] to contain anything after /user (assuming only one user and it's optional). I'm looking for the best way to do this, preferable

How to deploy Angular 2 application as a standalone (using dist folder)

懵懂的女人 提交于 2019-12-08 01:06:30
问题 I have finished a development of Angular 2 application and I need to deploy it. I need it to work standalone. So, I tried to move the content of dist folder inside a new apache website, but the routing mechanism doesn't work for some reason, I am getting 404 error when I try to go to /integrations route, for example. During the development, on angular 2 server, /integrations works and Angular 2 routing mechanism works and displays the component without problem. I need the standalone app to

Devise role based routing

半世苍凉 提交于 2019-12-07 23:56:24
I have an app with multiple users. Each user as a theoretical role (user, client, etc). I've designed a view/controller for each user type. I want to be able to login each type of user do a different root url and lock them to it. Originally I was going to add a column to Users in Devise called role and so I can differentiate the users. The problem I'm having is how to say in routes.rb if current_user.role == "client" root :to => 'controller#index' Once they are logged in to the page I also want to keep them from being able to visit any of my other paths ie: domain.com/calls domain.com/units I

How to Use Rails 3 Routes with Dynamic Segments

℡╲_俬逩灬. 提交于 2019-12-07 22:01:27
问题 In my Rails 3.2 application, there is an Exercise model with attributes muscle_group and grade_level. I've defined the following route with dynamic segments for it in config/routes.rb: # config/routes.rb match "/:muscle_group/grade-:grade_level/:id" => "exercises#show" Running bundle exec rake routes confirms that the route does indeed exist: /:muscle_group/grade-:grade_level/:id(.:format) exercises#show The database contains an Exercise record with: id = 5 muscle_group = "abdominal" grade

Symfony 2: How to get route defaults by route name?

痞子三分冷 提交于 2019-12-07 21:52:22
问题 Is it possible to retrieve info about a certain route by its name, or get a list of all routes? I need to be able to fetch the _controller value in defaults for any route, not only the current. Is this possible and how? P.S.: I found I could get the path to the routes YAML being used, but reparsing it seems unnecessary and heavy. 回答1: I am really good at answering my own questions.. To get routes use getRouteCollection() on the router ( $this -> get('router') -> getRouteCollection() inside a

Express.js res.render() and res.redirect()

点点圈 提交于 2019-12-07 20:26:24
问题 I have a route in my express app, which is supposed to do the following: Get some data from outside (OK) Show a HTML page with socket.io listening for messages (OK) Perform some calculations, which take a long time Send a message trough socket.io after each one one completed (OK) When all calculations are completed, show a result page (problem) So, a simplified version of my code is: module.exports = function(io) { // This is so I can use socket.io inside the route var express = require(

How to make resources redirect to another controller in rails

霸气de小男生 提交于 2019-12-07 19:04:31
问题 I have two models: Book and Magazine . There are few differences in terms of attributes, but i want them to share the same controller and views (the ones of Book's model). My question is : What is the correct way to set the routes of Magazine model inside routes.rb, considering that Book is already set as following resources :books This is a basic question, but i want to learn the best way instead of defining all the routes manually one by one Thanks! 回答1: You can configure the resource