rails-routing

How to get the current route in rails

青春壹個敷衍的年華 提交于 2019-12-03 19:28:53
问题 I am building some rails sample application in which I am having two models User and Projects. Association between both is user has_many projects. Now the question is I am willing to provide some drop down for user's projects on top and if some one click on that one it will take that to project show page. But if user is at edit page of one project and select other project from dropdown I want him to reach edit page of new selected project same case for show page any idea. The solution I am

Overriding a resource route to / (root) in Rails3: not changing the path helper?

我们两清 提交于 2019-12-03 17:39:12
问题 I am quite new to Rails3, I basically created a subscribers scaffolding, I only want my app to respond to new and create actions. So in config/routes.rb I defined: resources :subscribers, :only => [:new, :create] Which works this way GET /subscribers => subscribers#new POST /subscribers => subscribers#create Now I want my app to exhibit the subscribers resources at / (root) instead of /subscribers , so here is what I did: match '/' => "subscribers#new" match '/' => "subscribers#create" match

How can I create a Rails 3 route that will match all requests and direct to one resource / page?

青春壹個敷衍的年華 提交于 2019-12-03 15:14:15
问题 I have a rails app (Rails 3.0) that I need to temporarily take out of service. While this is in effect, I want to create a new route that will direct all requests to a single piece of static content. I have a controller set up to serve my static pages. I tried something like this: match '*' => 'content#holding' and match '*/*' => 'content#holding' to match a wildcard route as described here:Rails 3 route globbing without success. This is probably a really simple answer, but I couldn't figure

Overriding a resource route to / (root) in Rails3: not changing the path helper?

笑着哭i 提交于 2019-12-03 06:24:24
I am quite new to Rails3, I basically created a subscribers scaffolding, I only want my app to respond to new and create actions. So in config/routes.rb I defined: resources :subscribers, :only => [:new, :create] Which works this way GET /subscribers => subscribers#new POST /subscribers => subscribers#create Now I want my app to exhibit the subscribers resources at / (root) instead of /subscribers , so here is what I did: match '/' => "subscribers#new" match '/' => "subscribers#create" match '/' => "subscribers#thankyou" resources :subscribers, :only => [:new, :create] Which somehow works, but

How can I create a Rails 3 route that will match all requests and direct to one resource / page?

瘦欲@ 提交于 2019-12-03 05:50:16
I have a rails app (Rails 3.0) that I need to temporarily take out of service. While this is in effect, I want to create a new route that will direct all requests to a single piece of static content. I have a controller set up to serve my static pages. I tried something like this: match '*' => 'content#holding' and match '*/*' => 'content#holding' to match a wildcard route as described here: Rails 3 route globbing without success. This is probably a really simple answer, but I couldn't figure it out. / EDIT / Forgot to mention that I did have this rule at the very top of my routes.rb file.

How can I make routes from a Rails 3 engine available to the host application?

梦想的初衷 提交于 2019-12-03 05:34:42
I have a Rails 3 application with several engines containing additional functionality. Each engine is a separate service that customers can purchase access to. I am, however, having a problem with routes from the engines that aren't readily available to the controllers and views. controller: class ClassroomsController < ApplicationController .. respond_to :html def index respond_with(@classrooms = @company.classrooms.all) end def new respond_with(@classroom = @company.classrooms.build) end .. end app/views/classrooms/new.html.haml : = form_for @classroom do |f| .. f.submit config/routes.rb in

Rails 3 w/ Devise: How to set two separate homepages based on whether the user is authenticated or not?

孤街浪徒 提交于 2019-12-02 19:42:45
I am using Rails 3 and Devise to create an app where users arrive to the website and are shown a homepage containing a login and a signup form. This page has its own controller ("homepage") so it's route is root :to => "homepage#index" I want to display a different homepage if the users are already logged in. This would account to having the root point to root :to => "dashboard#index" Is there a way to have a conditional route in routes.rb, that would allow me to check whether the user is authenticated before routing them to one of those homepages? I tried using the following code but if I'm

Implementing /YYYY/MM/Title-Slug URL structure with Friendly_Id

杀马特。学长 韩版系。学妹 提交于 2019-12-02 15:21:25
问题 I'm really hoping someone can help this Rails n00b with this issue. I've been researching, trying, crashing(-and-burning) over the past few days on how to implement the standard /YYYY/MM/Title-Slug URL structure for a blog I'm putting together. I've discovered and successfully implemented Friendly_Id to handle the sluggification (along with history tracking), but for the life of me I can't get the Year/Month part of the routing problem resolved. Before I forget: I'm using Rails 4.2.3 and Ruby

/YYYY/MM/Title-Slug URL structure with Friendly_Id Solution Chokes on #new and #edit

老子叫甜甜 提交于 2019-12-02 07:41:53
I have a partial solution to my previous issue which is correctly displaying the posts#index and posts#show routes, but is choking after creating a post: ActionController::UrlGenerationError in PostsController#create No route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id, :month, :year] Extracted source (around line #32): 30 respond_to do |format| 31 if @post.save 32 format.html { redirect_to post_path, notice: 'Post was successfully created.' } 33 format.json { render :show, status: :created, location: @post } 34 else 35 format.html { render :new } …and editing a

/YYYY/MM/Title-Slug URL structure with Friendly_Id Solution Chokes on #edit

只谈情不闲聊 提交于 2019-12-01 09:12:59
Based on guidance I got in my earlier question in resolving my original issue to implement /YYYY/MM/Slug URL structure , I'm hoping to get some help in resolving an error I'm receiving when attempting to edit a post: No route matches [PATCH] "/blog/2015/09/example-post/blog/2015/09/example-post" Here are all the files in question (working off the same very simple scaffolded blog): $ rails new blog [...] $ cd blog # (Add friendly_id to Gemfile & install) $ rails generate friendly_id $ rails generate scaffold post title content slug:string:uniq [...] $ rake db:migrate routes.rb Rails.application