rails-routing

Rails 3 Routes: DRY members

柔情痞子 提交于 2019-12-08 23:53:33
问题 I need to add the following member methods to a number of resources, is there a way to DRY this up? member do get :votes post :up_vote post :down_vote end In my routes.rb resources :news do resources :comments do member do get :votes post :up_vote post :down_vote end end end resources :downloads do resources :whatever do member do get :votes post :up_vote post :down_vote end end end EDIT I've actually moved it out into a module like so: module Votable module RoutingMethods def votable

Routing Error — No route matches [POST] “/posts/new”

最后都变了- 提交于 2019-12-08 16:03:10
问题 I'm working through the rubyonrails.org 'blog tutorial', and get this error when I try to submit a 'post' : Routing Error --No route matches [POST] "/posts/new" I copied and pasted the code from the tutorial into my code. This should return a hash with the text and title of the post, but instead I get the above error. Here is my view: <%= form_for :post, url: posts_path do |f| %> <p> <%= f.label :title %><br> <%= f.text_field :title %> </p> <p> <%= f.label :text %><br> <%= f.text_area :text %

Routing issues with multi-part forms on Heroku

风流意气都作罢 提交于 2019-12-08 01:08:02
问题 This is a very bizarre problem, and unfortunately I can't provide a ton of information since I don't even know where to begin diagnosing the problem. I'm hoping somebody hear magically knows what to do, and I'm happy to clarify as necessary. For some reason, anytime I submit a new multi-part form with a file attachment on Heroku using Chrome, I am sent upon submitting to the default "index" action--that is, the page I would be sent to if I had submitted a GET instead of a POST. I'm using

Rails routing - how to add scope param to url_for helper?

别来无恙 提交于 2019-12-08 00:44:34
问题 I have resource bio and in views and link for add new bio is: = link_to "Add new bio", [:new, :admin, :bio] If I put resource :bio to scope like this: namespace :admin do scope "/:bio_type", :defaults => {:bio_type => "company"} do resources :bios end end This doesn't work = link_to "Add new bio", [:new, :admin, :bio, { bio_type: params[:bio_type] }] My question is how can I add scoped param to url_for helper? And can rails do this by default? p.s. new_admin_bio_path({bio_type: params[:bio

render a 404 page on routing error in rails

余生长醉 提交于 2019-12-07 18:28:18
问题 I'm trying to render the integrated 404 page in rails as an exception. I tried this but still getting the routing error page: posts_controller.rb def destroy if current_user.username == @post.email @post.destroy respond_to do |format| format.html { redirect_to posts_url } format.json { head :no_content } end else not_found end application_controller.rb def not_found raise ActionController::RoutingError.new('Not Found') end routes.rb Booklist::Application.routes.draw do get "pages/faq" get

Rails 3.2 f.file_field causes routing error

狂风中的少年 提交于 2019-12-07 16:48:48
问题 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])

Rails route: define root to namespace

☆樱花仙子☆ 提交于 2019-12-07 00:23:06
问题 I've got 2 controllers: app/ /controllers posts_controllers.rb /mobile posts_controllers.rb and my routes.rb looks like this: root :to => "posts#index" resources :posts namespace :mobile do root :to => "posts#index" resources :posts end but when i visit /mobile , it's anyway rendering index page of first controller, also tried this: namespace :mobile do root :to => "mobile/posts#index" resources :posts end but it's giving me error: uninitialized constant Mobile::Mobile I want to render the

match in rails routes.rb is redirecting too many times

谁都会走 提交于 2019-12-06 12:26:02
问题 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

render a 404 page on routing error in rails

限于喜欢 提交于 2019-12-06 11:44:28
I'm trying to render the integrated 404 page in rails as an exception. I tried this but still getting the routing error page: posts_controller.rb def destroy if current_user.username == @post.email @post.destroy respond_to do |format| format.html { redirect_to posts_url } format.json { head :no_content } end else not_found end application_controller.rb def not_found raise ActionController::RoutingError.new('Not Found') end routes.rb Booklist::Application.routes.draw do get "pages/faq" get "pages/about" devise_for :users resources :posts root 'posts#index' end view: <% if current_user.username

Rails routing - how to add scope param to url_for helper?

拟墨画扇 提交于 2019-12-06 07:38:47
I have resource bio and in views and link for add new bio is: = link_to "Add new bio", [:new, :admin, :bio] If I put resource :bio to scope like this: namespace :admin do scope "/:bio_type", :defaults => {:bio_type => "company"} do resources :bios end end This doesn't work = link_to "Add new bio", [:new, :admin, :bio, { bio_type: params[:bio_type] }] My question is how can I add scoped param to url_for helper? And can rails do this by default? p.s. new_admin_bio_path({bio_type: params[:bio_type]}) works fine, but it's just curious I believe you cannot make this with array params to link_to .