rails-routing

ActionController::MethodNotAllowed after reloading routes?

Hi, I have an application where I'm dynamically loading routes by a model, and calling ActionController::Routing::Routes.reload! after creating/updating that model. The problem is that after doing this, I'm receiving the following error when I try to hit that new route: ActionController::MethodNotAllowed Only get, head, post, put, and...

:id in URLs

I'm still new to ROR, so pardon the simplicity of the question... So http://www.example.com/controller/:id displays a record in my table, with :id being a number (1,2,3 etc.). Is there a way I can have :id in the URL be the value of a field in the displayed record? Such that I can have http://www.example.com/controller/record_field ??...

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

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 vie...

"Finding" the "parent" object in a nested resource relationship?

Say that I have two resources, Project and Task. A Project can have many Tasks; A Task belongs to one Project. Also say that I have Task nested under Project in routes.rb: map.resources :projects do |project| project.resources :tasks end Can one programmatically discover this relationship? Basically, I need to dynamically load an ar...

How do I add something to each route in Rails?

Is there an easy way to add a permanent string to every route in a Rails app, given that I already have quite a few resources specified and don't want to refactor all into a namespace? Can I do something along the lines of map.root 'myappnamehere' and have that string appended to the beginning of all routes? I realise that this is n...

Rails namespaced routing problem

We've got a rails app that keeps producing an error that we can't track down. The problem seems to lie with the routing but we're not sure what is happening. Out routes file looks like: ActionController::Routing::Routes.draw do |map| # Default map.home '', :controller => "home" # Admin map.admin_home 'admin', :controller => 'a...

Rails Routing

Hi All, I have built a new portal on Rails which can be accessed as say: https://xyz.com The problem with this is: 1.) It has 2 tabs – “ShipmentInfo” , “Aging Shipments Dashboard” both implemented using <li> tags and YUI library’s tabview. <ul class="yui-nav"> <li id="tab1" class="selected"><a href="#tab1">Shipment ...

What's the difference between :new, :collection and :member routes?

I've read the documentation, but I'm still not sure I understand everything. Especially why there's a :new parameter. As far as I understand, it could be replaced with the :collection parameter. So what's the difference between those three types of routes? ...

Accessing a resource in routes.rb by using attributes other than Id

I have the following in my routes.rb map.resources :novels do |novel| novel.resources :chapters end With the above defined route, I can access the chapters by using xxxxx.com/novels/:id/chapters/:id. But this is not what I want, the Chapter model has another field called number (which corresponds to chapter number). I want to access...

Ruby on Rails: Can I route a request directly to a view?

I have an admin section that has a sub-directory of the controllers directory. I.e., the directory app/controllers/admin/ holds a set of files, each containing a controller for handling a separate portion of the admin section. Now, I want to create a very simple ''admin homepage'' that just says something a la "welcome to the admin sect...

Complex Rails Routing

I would like to do something like github has with nested urls, and like http://stackoverflow.com/questions/1863292/how-do-i-route-user-profile-urls-to-skip-the-controller but not really sure how to go on with it. For example, looking at a commit they have: ':user/:repo/commit/:sha', with the controller being commit. How would I replica...

How can I redirect requests from Rails to a PHP subdomain?

Hello, I have a site, say, example.com, which is PHP. I am converting it to Rails, but there are three years worth of issues (like magazine issues) that I don't want to update. Thankfully, it seems that I chose an advantageous url format, ie. all issues start with two digits, then the name of the file in most cases example.com/00/aut...

RoR routing problem. Calling custom action, but getting redirected to show action

I am working on a project in ruby on rails and I am having a very difficult time with a basic problem. I am trying to call a custom action in one of my controllers, but the request is somehow getting redirected to the default 'show' action and I cannot figure out why. link in edit.html.erb: <%= link_to 'Mass Text Entry', :action=>"crea...

i18n redirection breaks my tests ....

I have a big application covered by more than a thousand tests via rspec. We just made the choice to redirect any page like : / /foo /foo/4/bar/34 ... TO : /en /en/foo /fr/foo/4/bar/34 .... So I made a before filter in application.rb like so : if params[:locale].blank? headers["Status"] = "301 Moved Permanently" redirect_to ...

Creating an Admin directory in Rails

I've been developing the CMS backend for a website for a few weeks now. The idea is to craft everything in the backend first so that it can manage the database and information that will be displayed on the main website. As of now, I currently have all my code setup in the normal rails MVC structure. So the users admin is /users and vide...

Rails: model_url for custom action

Let's say I have the simple rails blog app. And I have a custom action, like page_views which shows the number of views of the post. class PostsController < ApplicationController def page_views #show some page views end end And there is also an associated view in the app/views/Posts folder. Now, in the routes.rb I have:...

[Rails] map.resources with alternate primary key(s)

I have a Rails model Object that does not have an ID column. It instead uses a tuple of primary keys from two other models as its primary key, dependency_id and user_id. What I want to do is be able to do something like this in routes.rb: map.resources :object, :primary_key => [:dependency_id, :user_id] And for it to magically genera...

what is the equivalent in rails3 routes?

Hi, I have used this route in rails 2.3.5 - basically, I wanted to be able to parametrize my controller that I send to the named route. do_action "do_action/:controller" , :action => "do_action" what is the equivalent of this in rails3 routes? This doesn't work: match "do_action/:controller" , :to => ":controller#do_action", :as => ...

Restricting routes to nested resources in Rails

I am trying to create nested resources where the sub-resource doesn't have an existence of its own. e.g., an Address resource which is linked to a Person. My route declaration looks like so: map.resources :persons, :has_many => :addresses This gives me the following routes: person_addresses GET /persons/:person_id/a...

Rails Faking a Route

To be specific, I'm trying to get ActionController::Routing::Routes.recognize_path to recognize a route that is not in routes.rb, for testing purposes. Is it possible to somehow mock or dynamically add a route? I'm using Rspec with Mocha. ...