How can I solve error : Missing template sessions/create, application/create ?

58 views
Skip to first unread message

Jaimin Pandya

unread,
May 12, 2014, 9:25:36 AM5/12/14
to rubyonra...@googlegroups.com
When I run test by using following code:

$ bundle exec rspec spec/

then it should be pass which is written Michael hartl book in chapter 8
after section 8.2.4.

But i got error like:

Failure/Error: click_button "Sign in"
ActionView::MissingTemplate:
Missing template sessions/create, application/create with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
:coffee]}. Searched in:
* "/home/jaimin/rails3/rails_projects/sample_app/app/views"

How can I solve this error?

My authentication_pages_spec.rb :

require 'spec_helper'

describe "Authentication" do

subject { page }

describe "signin page" do
before { visit signin_path }

it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end

describe "signin" do
before { visit signin_path }

describe "with invalid information" do
before { click_button "Sign in" }

it { should have_selector('title', text: 'Sign in') }
it { should have_selector('div.alert.alert-error', text:
'Invalid') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end


describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Sign in"
end

it { should have_selector('title', text: user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end

Kind regards.

--
Posted via http://www.ruby-forum.com/.

tamouse pontiki

unread,
May 12, 2014, 12:53:44 PM5/12/14
to rubyonra...@googlegroups.com
On Mon, May 12, 2014 at 9:25 AM, Jaimin Pandya <li...@ruby-forum.com> wrote:
> When I run test by using following code:
>
> $ bundle exec rspec spec/
>
> then it should be pass which is written Michael hartl book in chapter 8
> after section 8.2.4.
>
> But i got error like:
>
> Failure/Error: click_button "Sign in"
> ActionView::MissingTemplate:
> Missing template sessions/create, application/create with
> {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder,
> :coffee]}. Searched in:
> * "/home/jaimin/rails3/rails_projects/sample_app/app/views"
>

This indicates that your application is trying to render a template
that matches your `create` method in your controller. Generally
speaking, you don't want to render templates from controller methods
that update your data base, such as `create`, `update`, and `destroy`,
since this could result in the user sending the same request if they
reload that page. So instead, you want to perform a redirect. Show us
the controller source code and maybe someone can help with that. Or if
this is enough a clue, carry on learning!


> How can I solve this error?
[snippysnip]

Jaimin Pandya

unread,
May 13, 2014, 1:02:13 AM5/13/14
to rubyonra...@googlegroups.com
My sessions_controller source code file as follow:

class SessionsController < ApplicationController
def new
end

def create
user = User.find_by_email(params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
# Sign the user in and redirect to the user's show page.

else
flash.now[:error] = 'Invalid email/password combination' # Not
quite right!
render 'new'
end
end

def destroy

Jaimin Pandya

unread,
May 13, 2014, 1:07:15 AM5/13/14
to rubyonra...@googlegroups.com
tamouse m. wrote in post #1145816:
I have post the controller source code. Could you help me with that?

Jaimin Pandya

unread,
May 13, 2014, 2:24:44 AM5/13/14
to rubyonra...@googlegroups.com
>> This indicates that your application is trying to render a template
>> that matches your `create` method in your controller. Generally
>> speaking, you don't want to render templates from controller methods
>> that update your data base, such as `create`, `update`, and `destroy`,
>> since this could result in the user sending the same request if they
>> reload that page. So instead, you want to perform a redirect. Show us
>> the controller source code and maybe someone can help with that. Or if
>> this is enough a clue, carry on learning!

Thank you very much for your clue. I have solved error.
Reply all
Reply to author
Forward
0 new messages