concept User in category ruby

This is an excerpt from Manning's book Rails 3 in Action.
This error occurs because you haven’t added a belongs_to association between the Ticket and User. Let’s open app/models/ticket.rb and add this line directly under the belongs_to :project line:
And I am signed in as "admin@ticketee.com" Couldn't find User with email = admin@ticketee.com (ActiveRecord::RecordNotFound)
Your engine is going to be a stripped-down version of this, showing only topics and posts. It’s a great example of how you can implement engine functionality, and it’s short enough to fit neatly into a chapter. You’re going to be using the User model from the host application (Ticketee) for all of your authentication needs too, which is kind of neat.
Within this engine you’re going to want to reference the User model from your application so that you are able to attribute posts and topics to whomever has created them. However, there’s a catch: within the application, the model that refers to the user in the system may not be called User! Therefore, you’re going to need to create a way to inform the engine of what this class is called from within the application.
The best way to inform the engine about the User model would be to have a file called config/initializers/forem.rb which will run when the application loads like all other initializers. This file would contain a single line, which would tell the engine what class represents users within this application, like this:

This is an excerpt from Manning's book Flexible Rails: Flex 3 on Rails 2.
Before we proceed, we should edit the User model to make the new first_name and last_name attributes mass-assignable from the params hash. (If that didn’t make sense, don’t worry—we’ll cover it later.) Edit the User model as shown in listing 3.3.
The create method
constructs a new User out of the params
and stores it in @user. It then calls @user.save!
, which will throw a RecordInvalid exception
if the save fails (because the save! method was called instead of the save method, which returns false). In normal operation, we use a respond_to block
; we also use a respond_to block in the rescue
. In that respond_to block, when HTML is the requested format, we render :action => 'new'
to render the new.rhtml file
; when XML is the requested format, we render the text "error"
.
But where did the error messages for the user come from? Let’s look at the User model; see listing 7.3.
Listing 7.3. app\models\user.rb
require 'digest/sha1' class User < ActiveRecord::Base has_many :tasks has_many :projects has_many :locations # Virtual attribute for the unencrypted password attr_accessor :password validates_presence_of :login, :email validates_presence_of :password, :if => :password_required? validates_presence_of :password_confirmation, :if => :password_required? validates_length_of :password, :within => 4..40, :if => :password_required? validates_confirmation_of :password, :if => :password_required? validates_length_of :login, :within => 3..40 validates_length_of :email, :within => 3..100 validates_uniqueness_of :login, :email, :case_sensitive => false before_save :encrypt_password ... endEight validation method calls (
–
) are used in the User class. These methods (validates_length_of, validates_presence_of, and so on) are class methods known as validation helpers. Calling them configures the Active Record model class to do specific validations before saving.
constructs a new User out of the params
and stores it in @user. It then calls @user.save!
, which will throw a RecordInvalid exception
if the save fails (because the save! method was called instead of the save method, which returns false). In normal operation, we use a respond_to block
; we also use a respond_to block in the rescue
. In that respond_to block, when HTML is the requested format, we render :action => 'new'
to render the new.rhtml file
; when XML is the requested format, we render the text "error"
.