rails-routing

Why do I get a No Route Matches [GET] “/products” when the route exists?

你。 提交于 2019-12-11 10:22:22
问题 I'm new to Ruby and Ruby on Rails, am using Ruby 1.9.2 and Rails 3.2.5 on Max OSX Lion, and am working my way through the book "Agile Web Development with Rails (4th Edition)". I've created their sample depot app using the following commands outlined in Chapter 6: rails new depot rails generate scaffold Product title:string description:text image_url:string price:decimal rake db:migrate rails server When I point Safari to "http://localhost:3000/products" I get the following Action Controller:

Rails - Dynamic routing based on host & ID

六眼飞鱼酱① 提交于 2019-12-11 10:03:03
问题 I have a rails application that contains many user pages. When a user wants to point a domain at this page, how would I do that? Right now I've tested out this, and it works - root :to => "controller#show", :id => 4, :constraints => {:host => "www.exampleurl.com"} but need to convert this to be dynamic, so that after I migrate a column into the model called domain it checks domain and serves it the proper ID. something like - root :to => 'controller#show', :id => ':id', :constraints => {:host

How to test a controller action that does not exist?

雨燕双飞 提交于 2019-12-11 09:15:03
问题 There are only two actions accessible in the ProductsController : # /config/routes.rb RailsApp::Application.routes.draw do resources :products, only: [:index, :show] end Tests are set up accordingly: # /spec/controllers/products_controller_spec.rb require 'spec_helper' describe ProductsController do before do @product = Product.gen end describe "GET index" do it "renders the index template" do get :index expect(response.status).to eq(200) expect(response).to render_template(:index) end end

Named route for non resource nesting

旧巷老猫 提交于 2019-12-11 08:24:02
问题 I'm trying to generate a link for a user to click to confirm their account. I'm wanting this: /users/:id/confirm/:code I've got this in my routes file: resources :users do member do get 'confirm/:confirmation_code', :action => 'confirm' end end I've tried: user_confirm_path(@user, @confirmation_code) confirm_user_path(@confirmation_code, @user) and many others but can't seem to get the right one. I guess I could always generate the link url myself but that doesn't seem the rails way. This is

Rails routes based on current user

大憨熊 提交于 2019-12-11 04:17:45
问题 I followed this rails cast to create authentication for a rails project. My routes currently look like this: Rails.application.routes.draw do resources :messages get "log_out" => "sessions#destroy", :as => "log_out" get "log_in" => "sessions#new", :as => "log_in" get "sign_up" => "users#new", :as => "sign_up" get "new_photo" => "users#edit", :as => "new_photo" root :to => "users#new" resources :users resources :sessions end How to I edit this file so that the root will be pointing to

How do I access all routes, when an App and an included AppEngine gem define controllers with the same name?

白昼怎懂夜的黑 提交于 2019-12-11 03:59:40
问题 I have an engine (developed by me / the company I work for) that we use on several different projects. I just converted it to work with rails 3.1 w/ assets pipeline and everything seems to be working... for the most part. My problem is that I need to extend the functionality of the UsersController with a little bit of app-specific spice, but I'm not sure about the best way to do it. The engine doesn't define a Users#show action, but this app does need it, so I added to the routes file:

Couldn't find [MODEL] without an Id : Rails 4 custom controller action

落爺英雄遲暮 提交于 2019-12-11 03:23:59
问题 I'm trying to create a JSON feed for certain data to pull into a graph I have in a partial. I keep running into "Couldn't find Dam without an Id", and none of the answers on SO seem to have the fix. My params seem to be passing through fine, and I'm a bit perplexed. routes.rb require "resque/server" Rails.application.routes.draw do mount Resque::Server, :at => "/resque" root 'home#index' get 'about', to: 'home#about' resources :dams, only: [:index, :show] do get 'count_data', to: 'dams#count

Best practices for static pages in rails app

旧时模样 提交于 2019-12-10 17:45:47
问题 I am developing a app in ruby on rails for a local business. The pages are 'static', but changeable through a backend CMS I am building for them. Is there a best practice to creating a controller for static pages? Right now I have a sites controller with all static routes, like this. routes.rb get "site/home" get "site/about_us" get "site/faq" get "site/discounts" get "site/services" get "site/contact_us" get "site/admin" get "site/posts" or would I be better off creating member routes for

Rails Routes - slash character vs hash character

倖福魔咒の 提交于 2019-12-10 13:18:15
问题 In urls and rails routing, what is the difference between using a slash character vs a pound sign (hash sign) character? These work get "/static_pages/about" get 'about', to: 'static_pages#about', as: :about These don't get "/static_pages#about" get 'about', to: 'static_pages/about', as: :about get 'about', to: '/static_pages#about', as: :about What code controls this behavior, and what is the deeper reason behind it? ANSWER: (The two people answered it very well, and I had trouble choosing

What to test in Rails routing?

蓝咒 提交于 2019-12-10 02:47:08
问题 I'm curious what people consider adequate/thorough testing of routes. A guy I work with seems to want to assert every route in our routes file, no matter how standard. I feel like this is a waste of time, but maybe I'm wrong and there is some value to this I'm unaware of. There are a few cases where I can see some value in routing. We still have a couple actions that respond to both GET and POST requests, although I've been meaning to get rid of those. We don't have any kind of crazy