rails-routing

grouping controller in subdirectories for nested resources

时间秒杀一切 提交于 2019-11-30 05:02:46
I would like to organize my controllers in subdirectories. Here is an example: routes.rb: resources :locations do resources :users end I would like to put my controller in the appropriate subdirectory: app/controllers/locations/users_controller.rb and the url would be (standard): /locations/1/users /locations/1/users/new /locations/1/users/10/edit ... If i had a namespace in my routes I could change my users_controller.rb to class Locations::UsersController < LocationsController end but it does not work with nested resources, instead I get the following error: Routing Error uninitialized

Routing error - uninitialized constant

强颜欢笑 提交于 2019-11-30 02:50:21
I could not fix this in Rails 3.2.12, maybe I am missing something. config/routes.rb get "home/index" root :to => "home#index" devise_for :users, :only => :omniauth_callbacks match 'users/auth/:provider/callback' => 'authentications#create' match '/auth/:provider/signout' => 'authentications#signout' app/controllers/authentication_controller.rb class AuthenticationsController < ApplicationController ... end app/models/authentication.rb class Authentication < ActiveRecord::Base ... end I think it should work with my current knowledge, but there is something that I miss. My kind question would

Routing with an optional parameter

霸气de小男生 提交于 2019-11-30 01:09:26
I added in the route file: map.show_book "/show_book/:name/year/:year", :controller => "book", :action => "show_version" I also added: map.show_book "/show_book/:name", :controller => "book", :action => "show_version" to show the latest book without specifying the year. But it doesn't work, it cannot find the route in "show_book/NAME" if I don't pass the year. Do you have some ideas why it doesn't work ? THANKS ! PS. I know that I can use year as parameter with "?year=XXXX", but I want to use the year as a part of the URL Benoit Garret Put the optional parts between parenthesis : map.show_book

Adding prefix to a named route helper under namespace

拈花ヽ惹草 提交于 2019-11-29 14:58:03
问题 This is how a common namespace looks like. namespace :admin do resources :posts end And it creates a named route like this one; new_admin_post_path Here's my question; how can I add a prefix (like "new" in this example) to a named route under namespace? Let's say my route definition likes this one; namespace :admin do get 'post/new' => 'posts#new', as: 'post' end And it's creates a named route like; admin_post_path I want to add "new" prefix to this named route and make it look like new_admin

Rails 3 link or button that executes action in controller

江枫思渺然 提交于 2019-11-29 14:03:41
问题 In RoR 3, I just want to have a link/button that activates some action/method in the controller. Specifically, if I click on a 'update_specs' link on a page, it should go to 'update_specs' method in my products controller. I've found suggestions to do this on this site: link_to "Update Specs", :controller => :products, :action => :update_specs However, I get the following routing error when I click on this link: Routing Error No route matches {:action=>"update_specs", :controller=>"products"}

i18n Routing To Mounted Engine - Ignoring locale

六眼飞鱼酱① 提交于 2019-11-29 04:32:25
I have an application (my_test_app) with working i18n support built. Currently, there are two language files available, FR & EN, and if I toggle back and forth between them, everything works as I expect to see it for non-engine functions such as the User index/show/edit/delete (ISED) options. Within my_test_app I have a Rails Engine mounted (my_engine) which has a controller & model set (engine_job). So, a workable URL should be http://0.0.0.0:3000/fr/my_engine/engine_job No matter what language I choose, however, it always shows up in EN. Examining the parameters shows: --- !ruby/hash

Engine routes in Application Controller

房东的猫 提交于 2019-11-29 02:50:01
问题 I have a before_filter hook in my main app's application controller that does something like: (It doesn't just put a link in the flash, there is a message, but it isn't relevant to the question, it just accesses the route in the method) class ApplicationController < ActionController::Base before_filter :set_link def set_link flash[:notice] = items_path end end This works fine for the app, however when I go into the controllers for an engine I made I get the exception No route matches {

Listing 'rake routes' for a mountable Rails 3.1 engine

流过昼夜 提交于 2019-11-28 23:09:07
I'm working on a mountable engine for use with Rails 3.1, and I want to list the engine's routes. I created the engine using: $ rails plugin new rails_blog_engine --mountable And edited the 'test/dummy/config/routes' file to read: Rails.application.routes.draw do mount RailsBlogEngine::Engine => "/blog" end ...and 'config/routes' to read: RailsBlogEngine::Engine.routes.draw do resources :posts end I want to list the routes generated for ':posts', but it's not clear how I can do this. When I run 'rake app:routes', I get only the "/blog" route: $ rake app:routes rails_blog_engine /blog {:to=

Routing with an optional parameter

China☆狼群 提交于 2019-11-28 21:56:29
问题 I added in the route file: map.show_book "/show_book/:name/year/:year", :controller => "book", :action => "show_version" I also added: map.show_book "/show_book/:name", :controller => "book", :action => "show_version" to show the latest book without specifying the year. But it doesn't work, it cannot find the route in "show_book/NAME" if I don't pass the year. Do you have some ideas why it doesn't work ? THANKS ! PS. I know that I can use year as parameter with "?year=XXXX", but I want to use

Rails query string with a period (or full stop).

左心房为你撑大大i 提交于 2019-11-28 13:47:19
I am currently trying to get a handle on RoR. I am passing in two strings into my controller. One is a random hex string and the other is an email. The project is for a simple email verification on a database. The problem I am having is when I enter something like below to test my page: http://signup.testsite.local/confirm/da2fdbb49cf32c6848b0aba0f80fb78c/bob.villa@gmailcom All I am getting in my params hash of :email is 'bob' . I left the . between gmail and com out because that would cause the match to not work at all. My routing match is as follows: match "confirm/:code/:email" => "confirm