routes

How to override routes path helper in rails?

泪湿孤枕 提交于 2020-01-12 09:02:08
问题 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,

Angularjs ngResource '@id'

会有一股神秘感。 提交于 2020-01-12 08:44:31
问题 I have a quick question. In angular js where (like which object) does the '@id' come from in the following piece of code from a rails app? var User = $resource("/users/:id", {id: '@id'}); I know it sets the default id. Thanks 回答1: From the AngularJs documentation: "If the parameter value is prefixed with @ then the value of that parameter is extracted from the data object (useful for non-GET operations)." This means that when calling a non-GET operation, like POST, you can pass the id as one

Possible to create this redirecting route in Rails?

倾然丶 夕夏残阳落幕 提交于 2020-01-11 15:08:08
问题 Is it possible to do a redirect in the routes file of a Rails app? Specifically, I'd like to forward /j/e to /javascripts/embed.js Right now the only way I can think to do it is to create a j controller with an e method that redirects to that. 回答1: Assuming rails version prior to 3. You can create a new RedirectController or tuck a single function away in an existing controller, to do something like the following: map.js_embed '/j/e', :controller => :redirect_controller, :action => :some

rails structuring routes/controller/views for nested resources

寵の児 提交于 2020-01-11 13:25:10
问题 I have rails app with the following structure: user has_many posts post has_many post_comments post_comment has_many comment_replies I'm planning to use the following routes to avoid deep nesting. resources :posts do resources :post_comments, module: :posts end resources :comments do resources :comment_replies, module: :post_comments #is this module a good choice? end This gives the following controller structure post_comments GET /posts/:post_id/comments(.:format) posts/comments#index POST

rails structuring routes/controller/views for nested resources

霸气de小男生 提交于 2020-01-11 13:25:02
问题 I have rails app with the following structure: user has_many posts post has_many post_comments post_comment has_many comment_replies I'm planning to use the following routes to avoid deep nesting. resources :posts do resources :post_comments, module: :posts end resources :comments do resources :comment_replies, module: :post_comments #is this module a good choice? end This gives the following controller structure post_comments GET /posts/:post_id/comments(.:format) posts/comments#index POST

Node.js and express : Routes

扶醉桌前 提交于 2020-01-11 11:42:49
问题 I have some trouble using the router from Express. I want to set up my routes with several files. I get my routes folder with 2 files: routes.js and inscription.js I do the following var inscription = require('./routes/inscription.js'); var routes = require('./routes/routes.js'); Then app.use('/', routes); app.use('/inscription', inscription); But only the routes from routes.js work... This is the content of routes.js var router = require('express').Router(); var bodyParser = require('body

Find default gateway ip address, rather than parsing proc filesystem

落爺英雄遲暮 提交于 2020-01-11 10:02:11
问题 How should I obtain the ip address of default gateway ? Rather than read entries from /proc , is there any standalone API useable ? 回答1: you can use libnl which is a library to communicate with the kernel via NETLINK sockets. a simple example to get the default route would be (please add error checking and the needed headers) void cb_route (struct nl_object *cb, void *arg) { struct rtnl_route *route = (struct rtnl_route*) cb; /* do what you need to do with rtnl_route object * e.g. copy it to

Zend Framework 2: get matched route in view

别等时光非礼了梦想. 提交于 2020-01-10 18:43:21
问题 I'm currently learning ZF2 by developing a small MVC application roughly based on the skeleton app. Right now I'm trying to hide some fixed HTML elements based on the route matched: just as an example, I don't want the main menu to show during the login phase. I can do that easily by passing toggle parameters as return values from the controller actions, but it doesn't feel right, so I'd like to just check the matched route from the layout and compose the layout accordingly. Problem is, I don

rails 3.1 ActionController::RoutingError (No route matches [GET] “/assets/rails.png”):

▼魔方 西西 提交于 2020-01-10 12:04:34
问题 Standard new rails app has issue showing the rails.png ActionController::RoutingError (No route matches [GET] "/assets/rails.png"): I have tried moving the .png file around to various places in assets and assets/images and also the older place 'public' or 'public/images' and changing the page but nothing has helped. Please answer if you have seen and resolved this. I have tried about 20 different combo's myself. Version: 'rails', '3.1.0.rc4' 回答1: I just had a problem throwing a similar error.

rails 3.1 ActionController::RoutingError (No route matches [GET] “/assets/rails.png”):

蹲街弑〆低调 提交于 2020-01-10 12:03:07
问题 Standard new rails app has issue showing the rails.png ActionController::RoutingError (No route matches [GET] "/assets/rails.png"): I have tried moving the .png file around to various places in assets and assets/images and also the older place 'public' or 'public/images' and changing the page but nothing has helped. Please answer if you have seen and resolved this. I have tried about 20 different combo's myself. Version: 'rails', '3.1.0.rc4' 回答1: I just had a problem throwing a similar error.