0

I'm not sure why but recently I tried changing my route for adding a new project to

/project/new and instead of rendering new.html.haml it renders show.html.haml and new is the parameter.

Inside my routes.rb

Mika::Application.routes.draw do
  root "pages#home"
  get '/contact' => "pages#contact"
  get '/about' => 'pages#about'
  get '/privacy' => 'pages#privacy'
  get '/tos' => 'pages#terms_of_service'

  post '/contact' => 'messages#contact'

  resources :projects, :only => [:index, :show]
  resources :projects, :only => [:update, :edit, :create, :post, :new], :constraints => { :subdomain => 'admin' }
end

I'm not entirely sure where to look to correct this issue or even when to start

In terminal I'm getting this

Started GET "/projects/new" for 127.0.0.1 at 2014-05-16 15:23:20 -0700
Processing by ProjectsController#show as HTML
  Parameters: {"id"=>"new"}
  Rendered projects/show.html.haml within layouts/application (0.1ms)
  Rendered layouts/_shim.html.haml (0.8ms)
  Rendered layouts/_header.html.haml (0.5ms)
  Rendered layouts/_footer.html.haml (0.2ms)
  Rendered layouts/_javascript.html.haml (0.0ms)
  Rendered layouts/_analytics.html.haml (0.0ms)
Completed 200 OK in 9ms (Views: 8.0ms | ActiveRecord: 0.0ms)

*EDIT Changing the routes file to this works

resources :projects, :only => [:update, :edit, :create, :post, :new], :constraints => { :subdomain => 'admin' }
resources :projects, :only => [:index, :show]

but it's still rendering create for parameters that don't exist with a blank page as the result

enter image description here

MikaAK
  • 2,334
  • 6
  • 26
  • 53

1 Answers1

0

You have defined these urls for show and new:

project       GET /projects/:id(.:format)  projects#show
new_project   GET /projects/new(.:format)  projects#new {:subdomain=>"admin"}

So if you are not using admin subdomain and entering the url /projects/new router matches it to more generic projects/show. The url format /projects/:id is being used where string new is interpreted as id.

Processing by ProjectsController#show as HTML
Parameters: {"id"=>"new"}

So if you want to access projects/new both with and without the admin subdomain, just specify so in the routes:

resources :projects, :only => [:index, :show, :new]
resources :projects, :only => [:update, :edit, :create, :post, :new], :constraints => { :subdomain => 'admin' }
Tumas
  • 1,697
  • 11
  • 9
  • This isn't the problem... The problem is that I'm not getting redirected to 404 page if i put in /projects/FAKEID, I'm getting the white page you see above – MikaAK May 17 '14 at 04:29
  • that's because you are using admin subdomain and show action is only available without it? Add show action to both lines in routes – Tumas May 17 '14 at 08:44
  • does you controller contains code for fetching the project? If so it should raise not found error if it is being executed of course. – Tumas May 17 '14 at 09:06
  • this also might be helpful http://stackoverflow.com/questions/2385799/how-to-redirect-to-a-404-in-rails – Tumas May 17 '14 at 09:07