rails-routing

Rails Responds with 404 on CORS Preflight Options Request

痴心易碎 提交于 2019-11-27 03:02:28
问题 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

How to create app-wide slug routing for Rails app?

拟墨画扇 提交于 2019-11-26 18:25:16
问题 I have a number of different models in the Rails app I'm working on. I've seen a number of sites use an app-wide slug routing approach. What do I mean by this? http://example.com/nick-oneill <-- This points to a User object http://example.com/facebook <-- This points to a Company object http://example.com/developers <-- This points to the users#index page I'm aware of to_param and creating reader-friendly slugs within apps, however I'm not aware of an approach to have root-level slugs for a

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

爷,独闯天下 提交于 2019-11-26 15:59: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? 回答1: 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 回答2: This does

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

孤者浪人 提交于 2019-11-26 11:15:09
问题 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

Rails Routes based on condition

我怕爱的太早我们不能终老 提交于 2019-11-26 11:10: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? 回答1: You can

Can Rails Routing Helpers (i.e. mymodel_path(model)) be Used in Models?

馋奶兔 提交于 2019-11-26 00:39:13
问题 Say I have a Rails Model called Thing. Thing has a url attribute that can optionally be set to a URL somewhere on the Internet. In view code, I need logic that does the following: <% if thing.url.blank? %> <%= link_to(\'Text\', thing_path(thing)) %> <% else %> <%= link_to(\'Text\', thing.url) %> <% end %> This conditional logic in the view is ugly. Of course, I could build a helper function, which would change the view to this: <%= thing_link(\'Text\', thing) %> That solves the verbosity