I'm working on a simple login function, based on ruby on rails. The problem is, that the value for session[:username] seems to be always empty, because the method asking for this always responds true. If I remove this part, the place where the username should be displayed is empty. All important codes can be found below. For any other information ask me.

show\_controller.rb:

```
class ShowController < ApplicationController
def login
@fehler1 = false
@fehler2 = false
if params[:username] != nil
    if User.find_by_username(params[:username]) == nil
        @fehler1 = true

    elsif User.find_by_username(params[:username]).pass == params[:pass]
        session[:username] = params[:username]
        redirect_to(:action => 'welcome')
    else
        @fehler2 = true
    end
end
end

def welcome
@fehler = false
if params[:logout] != nil
    session[:username] = nil
  redirect_to(:action => 'login')
end
if session[:username] == nil
    @fehler = true
else
    @username = session[:username]
end
end
end

```

application\_controller.rb:

```
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
end

```

login.html.erb

```
<h3>login</h3>
<% if @fehler1 %>
<font color="red"><b>User existiert nicht!<br /></b></font>
<% elsif @fehler2 %>
<font color="red"><b>Falsches Passwort!<br /> </b></font>
<% end %>
<p>Hier können sie sich anmelden!</p>
<form action="/show/login" method="post">
<table width="30%">
    <tr><td>Username:</td><td><input type="text" name="username"></td></tr>
    <tr><td>Passwort:</td><td><input type="password" name="pass"></td></tr>
    <tr><td></td><td><input type="submit" value="Login"></td></tr>
</table>
</form>

```

welcome.html.erb:

```
<% if @fehler %>
<font color="red"><b>Sie sind nicht eingeloggt!<br></b></font>
<a href="/show/login">Hier geht es zum login</a><br>
<% else %>
<h2>Willkommen <%= @username %></h2>
<form action="/show/welcome" method="post">
<input type="hidden" name="logout" value="true">
<input type="submit" value="Logout">
</form>
<% end %>

```

Gemfile:

```
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.rc2'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

gem 'thread_safe', '0.2.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0.rc2'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

```

I'm using rails version 4.0.0rc2 and ruby version 1.9.3p429. Thanks for your help :)