rails-routing

Rails 3.2 f.file_field causes routing error

北慕城南 提交于 2019-12-05 18:22:16
Tested on rails 3.2.12 and 3.2.11. In another rails 3.2.11 project I do not have this issue with f.file_field , but in current one I do and can't find a reason for this strange behaviour, so here is my question. I have a weird problem with update action. Here are relevant parts of code: routes: get "signup" => "users#new", :as => "signup" get "profile" => "users#profile", :as => "profile" resources :users do member do get :activate end end controller: def update @user = User.find(params[:id]) if @user.update_attributes(params[:user]) redirect_to user_path(@user), :notice => t('users_controller

Ruby on Rails redirect how to pass params in routes file

时光毁灭记忆、已成空白 提交于 2019-12-05 12:12:29
We recently changed the product name on our website from 'bracelets' to 'wristbands' and need to keep the old routes around for SEO purposes. Essentially, these routes www.hostname.com/products/bracelets/series-1/ www.hostname.com/products/bracelets/series-1/small-purple should route to www.hostname.com/products/wristbands/series-1/ www.hostname.com/products/wristbands/series-1/small-purple I am reading the tutorial here http://guides.rubyonrails.org/routing.html#redirection and looks like i'll be using the block syntax, but am still not sure how to do the route properly. I'm looking to learn

Why does mounting a route in Rails fail with “uninitialized constant API”?

大兔子大兔子 提交于 2019-12-05 10:30:08
I am working on an app that includes an API that is using the grape gem. Here is my Root Class: module API class Root < Grape::API rescue_from :all do |e| Rack::Response.new( [ "Error: #{e.message}" ], 500, { "Content-type" => "text/error" } ).finish end prefix "api" version 'v1', using: :path format :json error_format :json mount ::API::ServiceRequests end end Here is how I am mounting it in routes: mount API::Root => '/' The error I am receiving is: routes.rb:45:in block in ': uninitialized constant API (NameError)` The files are structured like app/api/root.rb and I have this bit of code in

ActionController::RoutingError: uninitialized constant Api::V1::ApiController

拥有回忆 提交于 2019-12-05 10:19:14
I have Rails 5 API project for controlling user tasks and I have the following error but not always for the same controller and route. ActionController::RoutingError: uninitialized constant Api::V1::ApiController I describe you a little bit my project to explain in more detail the error. App structure Routes scope module: 'api' do namespace :v1 do # => Login routes scope module: 'login' do match 'login', to: 'sessions#login', as: 'login', via: :post end # => Team routes scope module: 'team' do # => no admin routes resources :tasks, except: [:index] do collection do match ':view', to: 'tasks

Correct routing for short url by username in Rails

梦想的初衷 提交于 2019-12-05 04:29:59
问题 I am trying to replace user profile views of the sort /users/1 with /username I'm aware this means I'll need to check for collisions of various kinds. I've consulted the following similar SO questions: Ruby on rails routing matching username customize rails url with username Routing in Rails making the Username an URL: routing error with :username in url Here are the various failed routes.rb route definitions I've tried, and associated errors: match "/:username" => "users#show", via: "get"

What to test in Rails routing?

隐身守侯 提交于 2019-12-05 02:23:32
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 constraints with lambdas or anything, but that seems like it would be worth testing if we did. But for a normal

How to test route constraints with rspec

烈酒焚心 提交于 2019-12-04 22:58:10
I'm working on an application that will be primarily served as an API (other than a few minor views, such as session/registration, which will be "standard"). I like the approach that was finalized in Railscast #350: Versioning an API , and so followed it. My routes look like: namespace :api, :defaults => {:format => 'json'} do scope :module => :v1, :constraints => ApiConstraints.new(:version => 1, :default => false) do resources :posts, :only => [:create, :show, :destroy, :index] end scope :module => :v2, :constraints => ApiConstraints.new(:version => 2, :default => true) do resources :posts,

match in rails routes.rb is redirecting too many times

有些话、适合烂在心里 提交于 2019-12-04 20:18:11
I have a route that is suppose to match something like this localhost:3000/site/admin and redirect to localhost:3000/en/site/admin here is the route line that should match this routes.rb match '*path', to: redirect("/#{I18n.default_locale}/%{path}") but instead of matching it and redirecting to localhost:3000/en/site/admin, It's redirecting infite to this http://localhost:3000/en/en/en/en/en/en/en/en/en/en/en/en/en/site/admin (adds /en until browser complains about infite loop) Any idea why this infite loops is happening? Thanks EDIT Link to my my entire routes.rb file https://gist.github.com

rails get app root/base url

a 夏天 提交于 2019-12-04 08:49:40
问题 In my app I have a few APIs that under api domain. Now in one of the API I want to generate a url that pointing to the main domain, say test.com/blabla... I tried to use url_for but seems the default root_url or request.host is in api domain. Url_for will make it to be api.test.com/blabla.. while I want it to be test.com/blabla... Url_for can take a parameter host: ... to set it to be test.com/, the question is how can I get the root/base url (test.com) for host? root_url or request.host are

How do I make config.exceptions_app work with rspec

╄→尐↘猪︶ㄣ 提交于 2019-12-04 08:20:21
In my Rails 3.2 app, I'm trying to use config.exceptions_app to route exceptions through the routing table to render error-specific pages (especially one for 401 Forbidden). Here's what I've got so far for configuration: # application.rb config.action_dispatch.rescue_responses.merge!('Error::Forbidden' => :forbidden) config.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) } # development.rb config.consider_all_requests_local = false # test.rb config.consider_all_requests_local = false And now the meat of the matter: module Error class Forbidden < StandardError end end class