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)
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...
I observe that you render dashboard layout in groups index page please check path of dashboard .Is it in right place????
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.
Related
I'm very new to Rails and am trying to get started but have run into a problem, I've searched around and it seems like a lot of people have had the same problem but I either don't understand their solutions or don't seem to have the files that they changed to fix it,
I'm currently using Windows and running all commands through Git Bash, I have Ruby v2.2.4p230, and Rails v4.2.5.1, through Git Bash, I have just run these commands
cd ~/Desktop
rails new pinteresting
cd pinteresting
rails generate controller pages home
rails server
So now if I go to the localhost3000, it gives me the basic sample layout of the app which is fine, but then I try to visit the pages/home and I get one of three errors,
Missing helper file helpers/c:/users/acer_pc/desktop/pinteresting/app/helpers/application_helper.rb_helper.rb
Missing helper file helpers/c:/users/acer_pc/desktop/pinteresting/app/helpers/pages_helper.rb_helper.rb
Missing template pages/home, application/home with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "c:/Users/Acer-PC/desktop/pinteresting/app/views"
If it helps, this is the folder https://github.com/Fuledbyramen/pinteresting
I set up your project on my localhost and I am able to visit http://localhost:3000/pages/home without any issues.
You have set get 'pages/home' three times in routes.rb, one is enough.
Thank you guys for all the replies, finally figured it out, like all the other SO answers, its something to do with the capitalization of file names which I just couldn't figure out, so I just wrote it directly to /c instead of ~/desktop, then in application.html.erb just changed application in lines 5 and 6 to default and it works... Wasn't missing any files or needed to do any commands or anything
You've only generated the controller for pages and created an action called home for it. You have some additional steps needed, as well, to fill out all of the functionality.
There's a "fast" way to create the whole lot: scaffold. Try using this command:
rails generate scaffold pages
Since you've already created your controller, when it asks if you want to overwrite your controller, you can answer 'N' to the question. You can answer 'N' to any other questions that it asks, as well, especially if you've already made changes to any of the files, so that you don't lose those changes.
If you want to go the long way around, you'll also need to create at least some of these:
Model
Migration
Views
To create the Model, you can use another similar command:
rails generate model pages
This will create a page.rb file in your app/models directory. This maps to your database table that stores the details for each page.
You can also generate the Migration to create the pages database table, like so:
rails generate migration CreatePages
You'll need to provide the basic details of the pages table structure, following the Rails migration guidelines, which you can find here.
Finally, you'll need to create the Views for each action. This is primarily what's missing from your current implementation, because generating the controller doesn't generate the corresponding view files.
To do this, you'll want to create a new file called home.html.erb (if it doesn't already exist) in the app/views/pages directory. Simply having this file will be enough to make it past the point that you need, but you'll probably want to put something in it. Let's display the time:
<p>At the tone, it will be: <%= DateTime.now.strftime("%Y-%m-%d %H:%M:%S") %></p>
This should give you a decent starting point to build out the rest of what you need.
When you're starting out, however, try to use the scaffold generator until you're comfortable with where the pieces are all located and how to create them individually. And enjoy!
I have a model, controller and routes configured sucessfully with the name animegif.
In my show method, it looks under application/show instead of views/animegif/show.
Missing template animegif/show, application/show
"searched in /Users/myName/Desktop/testapp/app/views
My easy fix was adding this method to my animegif controller but I do not understand why is it not searching under views/animegif/show by default.
When I followed the rails tutorial by Michael Hartl, the paths were located correctly. Is there something I am doing wrongly?
Name of controller: animegifs_controller, model: animegif
For my routes I am using resources to generate the default routes for the model
def self.controller_path
"animegif"
end
If you read the error message once again you can see it first animegif/show directory of your views. If rails does not find the required template in that directory then it falls back to app/views. You are only getting this error message because either the show.html.erb is not there or you have any typo error.
If you are more curious about how rails finds your views, please refer to this post by Andy Wang. He has explained it in a better way.
Regarding the error message it is looking in app/views/animegif/ and app/views/application/ but cannot find the template. So you probably have a typo in the template's name show.html.erb (or other formats than html) in the respective directory.
I generated a new model called Comment.
rails g model Comment user_id:integer content:text
rake db:migrate
Then I create a simple partial view, that I intend to call from another controller/view.
Inside of a Product show view:
.comments
h3
| Questions and Answers:
small for #{#product.name}
= render 'comments/new'
Missing partial comments/new with {:locale=>[:en], :formats=>[:html],
:handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim, :coffee]}.
Searched in: *
"/Users/sergiotapia/Documents/Work/foobar/app/views"
I stopped and started the Rails application and it's still refusing to detect the partial. Am I overlooking something?
I would prefer not to move the comment form to the Products folder.
Incorrect File Extension
Rename partial file to _new.html.slim. Currently html is misspelt as hmtl.
Try this out:
2.2.4 Rendering an Arbitrary File
The render method can also use a view that's entirely outside of your
application (perhaps you're sharing views between two Rails
applications):
render "/u/apps/warehouse_app/current/app/views/products/show"
Rails determines that this is a file render because of the leading
slash character. To be explicit, you can use the :file option (which
was required on Rails 2.2 and earlier):
render file:"/u/apps/warehouse_app/current/app/views/products/show"
The :file option takes an absolute file-system path. Of course, you
need to have rights to the view that you're using to render the
content.
Taken from here: http://guides.rubyonrails.org/layouts_and_rendering.html
EDIT:
Oh sure, the file name is not correct, didn't see that. ;) See Kirti Thorat's answer.
I'm a newbie in ruby on rails Web-Programming. Today I tried to set up Ruby programming language and also the Rails framework. Ruby works properly, I made a first Test-Class Successfull. Only setting up my Rails framework prepares me some problem.
I made a test_app and i tried to run it.
rails new test_app
rails s
I realized that the the routes was commented in routes.rb and I uncommented it.
I changed #root :to => 'welcome#index' to root :to => 'welcome#index'.
I also realized that I do not had a controller for the page welcome/index and i created it
with rails g controller Welcome index.
But It do not work yet? Anybody an idea?
Template is missing
Missing template welcome/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "D:/Davide Giunta/Development/workspace[ruby]/test_app/app/views"
Ruby Version: 1.9.3p368
Gem Version: 1.8.24
Rails Version: 3.2.11
rails g controller will only create the controller part, you also need to create a corresponding view file, in this case, you want app/views/welcome/index.html.erb
Using scaffold (only while learning), or resource for your generator might be faster. (I usually create them all by hand these days)
The answer from Jim Deville is correct. You need to create corresponding view file of your controller's action (action_name.html.erb) and place it to views dir under subdirectory named like your controller.
See basics of Rails here http://guides.rubyonrails.org/getting_started.html.
When you want to create action with controller, view and model you should use rails g scaffold SomeName also see http://guides.rubyonrails.org/getting_started.html#getting-up-and-running-quickly-with-scaffolding.
I'm trying to create two static pages and I have the following error:
Missing template static_pages/index with {:formats=>[:html], :locale=>[:en, :en], :handlers=>[:rhtml, :rxml, :builder, :erb, :rjs]} in view paths "F:/assignment/app/views"
I am new to rails and web development in general, so it's probably something simple.
I have followed this link to get to the stage I am now at: Static pages in Ruby on Rails
I am trying to create two static pages, one called About and one called Help in a basic blog application. When I have created the controller I have called it 'static_pages' as I already have a pages controller.
Can anybody offer any advice on where I'm going wrong?
I hope I understand you correctly if I say you want a path like localhost:3000/About
In that case, you want to create a method with the same name as the view (About.html) in your static_pages controller.
def About
end
(Notice case sensitivity)
The About.html file should be placed within the /static_pages directory. And in the routes.rb file, you should have:
match '/About' => 'static_pages#About'
Hope this helps.