Andre Zimpel
Andre Zimpel

Reputation: 2343

Very strange routing error in rails 3

I got a controller called MeController. It has a bunch of actions like spaces and projects.

The spaces action does the following:

  def spaces
    @spaces = current_user.spaces

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @note }
    end
  end

The view just renders an other index template like:

<%= render :template => "spaces/index" %> 

This works perfectly but now the stränge part begins... :S

This is the project action:

  def projects
    @projects = current_user.projects

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @projects }
    end
  end

The view renders also an index template:

<%= render :template => "projects/index" %> 

But for the projects I get the following error:

Routing Error

No route matches {:action=>"edit", :controller=>"spaces", :id=>nil}

I just don't get why it should be an Routine Error with the action edit and the controller spaces. :/

Here are my routes:

# Profiles & Current User
  resources :profiles

  get "me" => "profiles#show", :as => "current_user"
  get "me/spaces", :as => "current_user_spaces"
  get "me/projects", :as => "current_user_projects"
  get "me/tasks", :as => "current_user_tasks"
  get "me/notes", :as => "current_user_notes"
  get "me/discussions", :as => "current_user_discussions"
  get "me/files", :as => "current_user_files"

  # Permissions
  resources :permissions

  resources :spaces do
    resources :projects do
      resources :tasks
      resources :notes
    end
  end

  devise_for :users

  root :to => redirect("/me/spaces")

Hope somebody has a hint for me! :)

Upvotes: 0

Views: 59

Answers (1)

moritz
moritz

Reputation: 25757

So my guess would be:

In your template (projects/index), you are using url helpers like url_for or link_to with links to specific projects. The issue is that the projects have nested routing within your spaces resource. That's why you have to provide any url helper with a reference to both, space and project when you want it to generate an url to a project.

RoutingError is also thrown in case an url helper doesn't know how to construct an url.

This is a long shot, but I hope it helps.

Upvotes: 1

Related Questions