rails-routing

Rails Responds with 404 on CORS Preflight Options Request

大兔子大兔子 提交于 2019-11-28 09:35:18
I'm creating a set of services using Rails 4, which I am consuming with a JavaScript browser application. Cross-origin GETS are working fine, but my POSTs are failing the preflight OPTIONS check with a 404 error. At least, I think that's what's happening. Here are the errors as they appear in the console. This is Chrome 31.0.1650.63 on a Mac. OPTIONS http://localhost:3000/confessor_requests 404 (Not Found) jquery-1.10.2.js:8706 OPTIONS http://localhost:3000/confessor_requests No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore

RSpec not finding my named routes

我的未来我决定 提交于 2019-11-28 04:22:47
问题 I'm having an inexplicably hard time getting my named routes to work within my rspec tests. Here's what I'm seeing: 1) Home GET / works! Failure/Error: get root_path NameError: undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe13b0c1538> # ./spec/requests/home_spec.rb:6:in `block (3 levels) in <top (required)>' 2) Home GET / shows products! Failure/Error: get products_path NameError: undefined local variable or method `products_path' for

Adding an action to an existing controller (Ruby on Rails)

独自空忆成欢 提交于 2019-11-28 04:21:09
I am new to Ruby on Rails, I have completed the Blog Tutorial . I am now trying to add an additional action to the controller, called 'start'. def start end I have added a view page "app/views/posts/start.html.erb" containing nothing but simple html. When I go to /posts/start i get the following error. ActiveRecord::RecordNotFound in PostsController#show Couldn't find Post with ID=start I understand the error, the show action is being executed and start is not a valid ID. Why doesn't the start action get executed, is there some part of the MVC architecture or configuration I am missing ? Below

i18n Routing To Mounted Engine - Ignoring locale

送分小仙女□ 提交于 2019-11-27 18:23:57
问题 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

Routes with Dash `-` Instead of Underscore `_` in Ruby on Rails

大城市里の小女人 提交于 2019-11-27 18:14:30
I want my urls to use dash - instead of underscore _ as word separators. For example controller/my-action instead of controller/my_action . I'm surprised about two things: Google et al. continue to distinguish them. That Ruby on Rails doesn't have a simple, global configuration parameter to map - to _ in the routing. Or does it? The best solution I've is to use :as or a named route. My idea is to modify the Rails routing to check for that global config and change - to _ before dispatching to a controller action. Is there a better way? With Rails 3 and later you can do like this: resources

Listing 'rake routes' for a mountable Rails 3.1 engine

百般思念 提交于 2019-11-27 14:34:44
问题 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

How can I use Rails routes to redirect from one domain to another?

老子叫甜甜 提交于 2019-11-27 12:26:53
My app used to run on foo.tld but now it runs on bar.tld. Requests will still come in for foo.tld, I want to redirect them to bar.tld. How can I do this in rails routes? Lukas Eklund This works in Rails 3.2.3 constraints(:host => /foo.tld/) do match "/(*path)" => redirect {|params, req| "http://bar.tld/#{params[:path]}"} end This works in Rails 4.0 constraints(:host => /foo.tld/) do match "/(*path)" => redirect {|params, req| "http://bar.tld/#{params[:path]}"}, via: [:get, :post] end This does the job of the other answer. Though in addition, it preserves query strings as well . (Rails 4): #

Adding an action to an existing controller (Ruby on Rails)

为君一笑 提交于 2019-11-27 05:19:40
问题 I am new to Ruby on Rails, I have completed the Blog Tutorial. I am now trying to add an additional action to the controller, called 'start'. def start end I have added a view page "app/views/posts/start.html.erb" containing nothing but simple html. When I go to /posts/start i get the following error. ActiveRecord::RecordNotFound in PostsController#show Couldn't find Post with ID=start I understand the error, the show action is being executed and start is not a valid ID. Why doesn't the start

Rails 3 link_to (:method => :delete) not working

倖福魔咒の 提交于 2019-11-27 04:33:22
I'm having trouble with my verbs in Rails ... viewing a page for a resource (Dog) which has_many (Fleas). Embedded in dog's show.html.haml is a call to render @dog.fleas which automatically(?) finds & uses the template in "fleas/_flea.html.haml" to list each flea associated with said dog. this displays correctly. whew! Now, next to each flea I've put a "Kill Flea" link that goes to a url: //localhost:3000/dogs/1/fleas/7 . Which is generated by: = link_to("Kill Flea", [ flea.dog, flea ], :method => :delete, :confirm => "Sure? A bunny will die") but every time that link is clicked there is no

Rails Routes based on condition

送分小仙女□ 提交于 2019-11-27 04:31:41
I have three roles: Instuctor, Student, Admin and each have controllers with a "home" view. so this works fine, get "instructor/home", :to => "instructor#home" get "student/home", :to => "student#home" get "admin/home", :to => "admin#home" I want to write a vanity url like below which will route based on the role of the user_id to the correct home page. get "/:user_id/home", :to => "instructor#home" or "student#home" or "admin#home" How do I accomplish this? tadman You can't do this with routes because the routing system does not have the information required to make this decision. All Rails