Template is missing in RoR App

…衆ロ難τιáo~ 提交于 2019-12-25 10:17:08

问题


I created an app "guestbook" in rails, I then created a controller using "rails g controller entries". After that I created index.html in app/views/entries/ and in it I wrote following :-

 <h1>Hello <%= @name %></h1>
<%= form_tag :action => 'sign_in' do %>
<p>Enter your name:
<%= text_field_tag 'visitor_name', @name %></p>
<%= submit_tag 'Sign in' %>
<% end %>

and in entries_controller.rb it is written :-

class EntriesController < ApplicationController
    def sign_in
        @name = params[:visitor_name]
    end
end

after that when I run "rails s" and go to :-

localhost:3000/entries/

it shows me a proper view which is supposed to be there.

when I enter the name and press button it routes to localhost:3000/entries/sign_in and it says the following error :-

Template is missing

Missing template entries/sign_in, application/sign_in with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/redblink/rbtest/guestbook/app/views"

please let me know what is happening ???


回答1:


Fix:

This error is occurred because rails server is unable to find template with name sign_in.html.erb in app/views/entries directory. You should create it.

Explanation:

By default rails tries to find template with same name as your action has i.e. sign_in in your case. If you don't want to create or render this default template, you need to specify another template to render by using render method in your action. render method is defined in ActionController::Base class




回答2:


You have to create a ERB template in /home/redblink/rbtest/guestbook/app/views/sign_in.html.erb with the contents you want to show to the user.



来源:https://stackoverflow.com/questions/11778802/template-is-missing-in-ror-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!