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.
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 am new to Rails and was trying to create a new page, when I somehow (and I don't know where or when) the PagesController got deleted. So I created another one in the controllers folder
class PagesController < ApplicationController
def home
end
def about
end
end
And now this error message pops up:
Template is missing: Missing template pages/home, application/home with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}
What did I do and how do I fix it?
Well if you can't see the trash to recover the files that you deleted or try "ctrl + z" (in windows) or "cmd + z" (in mac) to undo the deletion then you would need to create the files from the scratch, i'm assuming that you don't have code in those files.
Just go to the terminal, go to the project folder in the terminal and write this command:
rails g scaffold_controller pages home about
With that you will recreate the files that you deleted and keep the files that you didn't delete, as you can see with the command you are creating just the controller and the "home" and "about" views. This will not create the model, so you should be calm about that.
I hope it helps :D
You have no app/views/pages/home.* template. You need to create that file. It will (probably) need a .html.erb extension, but that depends on which template language your using.
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.
I dropped the gem into the gem file, bundle installed it.
Have this in my application.rb:
require 'pdfkit'
config.middleware.use PDFKit::Middleware, :print_media_type => true
Doing rake middleware, I see 'use PDFKit::Middleware' in there.
I have this in my routes
match "/option_invoice/view_invoice/(/:id)" => "option_invoice#view_invoice"
Now when I go to http://0.0.0.0:3000/option_invoice/view_invoice/2.pdf, I got the missing template error. The page without the .pdf displays perfectly fine.
Missing template option_invoice/view_invoice, application/view_invoice with {:formats=>> >[:pdf], :locale=>[:en], :handlers=>[:coffee, :erb, :builder, :arb]}.
I'm on rails 3.2.2 if that helps.
Any help?
Basically you're just missing a template in given paths that corresponds to view_invoice.pdf.erb or view_invoice.pdf.haml or whatever you are using.
Either you create that and render whichever view you want in the PDF or you override the default template pulled by PDFKit.
I would recommend the first variant, this makes the rendered PDF independent of your views (kind of).
Cheers!
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.