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 ???
Fix:
This error is occurred because rails server is unable to find template with name
sign_in.html.erbinapp/views/entriesdirectory. 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
rendermethod in your action.rendermethod is defined in ActionController::Base class