Ok, so just moved devise_for at the top of the routes file.

This is my users controller. I removed a lot of code to isolate the 
problem, but even without that code, it shouldn't tell me "user is 
already sign in" and send me to the root url.

---------------------------------------------------------------
  def index
    @companies = Company.all(:conditions => ["account_id == ?", 
current_user.account_id])
    @users = User.all(:order => 'email')

    respond_to do |format|
      format.html # index.html.erb
    end
  end

  def show
    @user = User.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
    end
  end

  # POST /users
  # POST /users.xml
  def create
@user = User.new
    respond_to do |format|
      if @user.save
        format.html { redirect_to(edit_user_path(@user), :notice => 
'User was successfully created.') }
        format.xml  { render :xml => @user, :status => :created, 
:location => @user }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @user.errors, :status => 
:unprocessable_entity }
      end
    end
  end

  def new
    @user = User.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @user }
    end
  end
---------------------------------------------------
User model
  belongs_to :account
  belongs_to :role
  belongs_to :company

  has_many :tickets , :foreign_key => 'requestor_id' #, :class_name => 
'Ticket'
  # has_many :tickets, :class_name => 'Ticket', :foreign_key => 'ti'
  # has_many :requestors, :class_name => 'User', :foreign_key => 
'requestor_id'
  # has_many :assignees, :class_name => 'Ticket'
  # has_many :solvers, :class_name => 'Ticket'

  validates :email, :username, :first_name, :last_name, :presence => 
true, :uniqueness => true
  validates :role_id, :account_id, :company_id, :presence => true

  # has_many :tickets, as => :assignee
  # has_many :tickets

  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :lockable, :timeoutable and 
:omniauthable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :username, :email, :password, :password_confirmation, 
:remember_me, :account_id, :company_id, :title, :last_name, :first_name

--------------------------------------------------------
Company model

class Company < ActiveRecord::Base
  has_many :users
  has_one :account
  validates :name, :account_id, :presence => true
end
-------------------------------------------------
Registration Controller
class Users::RegistrationsController < Devise::RegistrationsController

  def new
  end

  def create
  end
end
--------------------------------------
routes

devise_for :users, :controllers => { :registrations => 
'users/registrations' }

  resources :companies
  resources :users

  resources :companies do
    resources :users
  end
-------------------------------------------------------

new user form

<h1>company id: <%= params[:company_id] %></h1>

<%= form_for(@user) do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this 
user from being saved:</h2>

      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :first_name %><br />
    <%= f.text_field :first_name %>
  </div>
  <div class="field">
    <%= f.label :last_name %><br />
    <%= f.text_field :last_name %>
  </div>

  <div class="field">
    <%= f.label :username %><br />
    <%= f.text_field :username %>
  </div>

  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </div>

  <% # Display password fields only if user is creating a new user %>
  <% if params[:action] == 'new' %>
  <div class="field">
  <%= f.label :password %><br />
  <%= f.password_field :password %>
  </div>

  <div class="field">
  <%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %>
  </div>
  <% end %>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to