How can I render the application.html.erb
view in a rails app?
I've tried adding a method to the application_controller.rb
controller:
def amethod
end
And then updating the routes.rb
file:
get '/', to: 'application#amethod'
to no avail. I get this error message:
Missing template application/amethod with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/Users/peterward/Directory/mini-project/app/views"
It's looking for the html.erb
view in the app/views
directory instead of the app/views/layouts
directory.
How can I change this?
Rails is looking for a file named views/amethod.html.erb
, the layout that you're using application.html.erb
is not meant to hold the view for your controller action. The layout will yield to the controller action named view.
I suggest you read Rail's render and layout guide.
The quickest solution to solving your error would be to create a blank file: app/views/amethod.html.erb
However, this does not really address your problem, because I doubt you really just want to render a layout.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.