Having trouble with the welcome screen

Subscribe to Having trouble with the welcome screen 4 post(s), 2 voice(s)

 
Avatar theelbster 3 post(s)

I’m at the point in this exercise where I can create a user (name, email, password, password-conf), but when I submit that form, I get the following error:

ActionController::MethodNotAllowed
Only get, head, post, put, and delete requests are allowed.
RAILS_Root: /usr/local/exercisr
Headers:
(“cookie”=>[], “Cache-Control”=>”no-cache”, “Allow”=>”GET, HEAD, POST, PUT, DELETE”}

As far as I can tell, there is a problem with the welcome path, but I can’t figure it out. Any help would be appreciated.

Here are the contents of my files:
.../config/routes.rb:
ActionController::Routing::Routes.draw do |map| map.resources :exercisers map.home ’’, :controller => ‘sessions’, :action => ‘new’ map.resources :users, :sessions map.welcome ’/welcome’, :controller => ‘sessions’, :action => ‘welcome’ map.signup ’/signup’, :controller => ‘users’, :action => ‘new’ map.login ’/login’, :controller => ‘sessions’, :action => ‘create’ map.logout ’/logout’, :controller => ‘sessions’, :action => ‘destroy’ map.connect ’:controller/:action/:id’ map.connect ’:controller/:action/:id.:format’
end

.../app/controllers/application.rb:
class ApplicationController < ActionController::Base helper :all # include all helpers, all the time before_filter :login_from_cookie session :session_key => ‘_exercisr_session_id’ include AuthenticatedSystem

  1. See ActionController::RequestForgeryProtection for details
  2. Uncomment the :secret if you’re not using the cookie session store protect_from_forgery # :secret => ‘c3f7d2ecee34d3b3ff8e9117984956ee’
    end
.../app/controllers/sessions_controller.rb:
  1. This controller handles the login/logout function of the site.
    class SessionsController < ApplicationController # render new.rhtml def new end
def create
  self.current_user = User.authenticate(params[:login], params[:password])
  if logged_in?
    if params[:remember_me] == "1" 
      current_user.remember_me
      cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expire        s_at }
    end
    redirect_back_or_default(welcome_path)
    flash[:notice] = "Logged in successfully" 
  else
    render :action => 'new'
  end
end
def welcome
end
def destroy
  self.current_user.forget_me if logged_in?
  cookies.delete :auth_token
  reset_session
  flash[:notice] = "You have been logged out." 
  redirect_back_or_default(login_path)
end
end

.../app/controllers/users_controller.rb
class UsersController < ApplicationController # render new.rhtml def new end

def create
    @user = User.new(params[:user])
    @user.save!
    self.current_user = @user
    redirect_back_or_default(welcome_path)
    flash[:notice] = "Thanks for signing up!" 
  Rescue ActiveRecord:RecordInvalid
    render :action => 'new'
  end
end

end

.../app/views/sessions/new.html.erb:
<% form_tag sessions_path do ->

<label for="login">Login</label>

<= text_field_tag ‘login’ %>

<label for="password">Password</label>

<%= password_field_tag ‘password’ %>

<!- Uncomment this if you want this functionality

<label for="remember_me">Remember me:</label>
<%= check_box_tag ‘remember_me’ %>


->

<= submit_tag ‘Log in’ %>


< end -%>

.../app/views/sessions/welcome.rhtml:

Welcome to Exercisr


A RESTful place to keep track of your workouts

 
Avatar theelbster 3 post(s)

UPDATE: I finally figured it out. I had to move the map.welcome line to after map.logout. I don’t at all understand why, but it works at least.

 
Avatar EldonAlameda Administrator 216 post(s)

Hi theelbster,

What did your routes look like before? and after?

 
Avatar theelbster 3 post(s)

Hi Eldon,

It looks like copy/paste turned out horribly here. Also, I should mention that there may be version conflicts (btw the version written about in your book and the one I’m actually using) at play here.
I’m using OSX 10.4.11
ruby -v => ruby 1.8.6
rails -v => Rails 2.1.0

Routes.rb before:
ActionController::Routing::Routes.draw do |map|
map.resources :exercisers
map.home ’’, :controller => ‘sessions’, :action => ‘new’
map.resources :users, :sessions
map.welcome ’/welcome’, :controller => ‘sessions’, :action => ‘welcome’
map.signup ’/signup’, :controller => ‘users’, :action => ‘new’
map.login ’/login’, :controller => ‘sessions’, :action => ‘create’
map.logout ’/logout’, :controller => ‘sessions’, :action => ‘destroy’
map.connect ’:controller/:action/:id’
map.connect ’:controller/:action/:id.:format’
end

routes.rb after:
ActionController::Routing::Routes.draw do |map|
map.resources :exercisers
map.home ’’, :controller => ‘sessions’, :action => ‘new’
map.resources :users, :sessions
map.signup ’/signup’, :controller => ‘users’, :action => ‘new’
map.login ’/login’, :controller => ‘sessions’, :action => ‘create’
map.logout ’/logout’, :controller => ‘sessions’, :action => ‘destroy’
map.welcome ’/welcome’, :controller => ‘sessions’, :action => ‘welcome’
map.connect ’:controller/:action/:id’
map.connect ’:controller/:action/:id.:format’
end