Mitch
Mitch

Reputation: 1069

Missing Template though routing seems to work

When I generate a new controller, under a subfolder, it now cannot find the templates, even though other controllers in the same 'structure' are working:

I have the following controller which sits in app/members/group_controller.rb (created by a rails g controller Members::Group command)

class Members::GroupController < ApplicationController
  def index
    render :layout => 'dashboard'
  end
end

I have a template in views/members/group/index.html.erb

I have the following relevant line in routes.rb (ie leaving out some others for clarity):

namespace :members do
    match '/group' => 'group#index'
end

rake routes shows me the following relevant line:

members_group            /members/group(.:format)                       members/group#index

When I type the url http://127.0.0.1:3000/members/group, I get the Template Missing error as follows:

Template is missing

Missing template members/group/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :arb, :coffee]}. Searched in: * "/Users/mitch/Documents/Development/TME/app/views" * "/Users/mitch/.rvm/gems/ruby-1.9.2-p290/bundler/gems/active_admin-7c3e25f30224/app/views" * "/Users/mitch/.rvm/gems/ruby-1.9.2-p290/gems/kaminari-0.13.0/app/views" * "/Users/mitch/.rvm/gems/ruby-1.9.2-p290/gems/devise-2.0.0/app/views"

The routing is working to the index method, because I can eg put in a redirect and it gets acted upon, but I cannot get the template to display.

Why so?

Thanks

(Rails 3.1)

Upvotes: 0

Views: 1629

Answers (3)

Pat Ced
Pat Ced

Reputation: 1

I had the exact same problem. When I used terminal to navigate to the directory and listed the files in /layouts, I had one layout file appear as a red, archived file. I have no idea why.

To fix it: simply copy&paste the code from the layout file, delete the layout file (rm "file"), and then create the same layout using the terminal via:

touch file_name.html.erb

Paste your code into the new file and it should work.

Upvotes: 0

Mitch
Mitch

Reputation: 1069

This seems to be linked to how I generate the controller in the first place.

I used upper case as follows:

rails g controller Members::Group (and tried a few other test controllers similarly, destroying them and recreating them)

When I destroyed the controller and ran the lower case equivelant:

rails g controller members::group all works fine and the templates can be found

I can't find any info elsewhere to support this though...

Upvotes: 1

Kashiftufail
Kashiftufail

Reputation: 10885

I observe that you render dashboard layout in groups index page please check path of dashboard .Is it in right place????

Upvotes: 0

Related Questions