Marnen Laibow-Koser wrote:
> Ralph Shnelvar wrote:
>> Newb here.
>> 
>> I have a form and a value that is being displayed ... and I have no idea
>> where the value came from.
>> 
>> I have done a
>>   <%= debugger; '' %>
>> in the form and, indeed, the debugger stops at the statement.
>> 
>> I have tried to trace through the code to see where the value came from
>> ... and I gave up.
>> 
> 
> You're going to have to describe the problem in more detail, with actual 
> code, if you want help.  And what do your tests say?
> 
>> 
>> 
>> 
>> So ... what in Rails initializes the fields of a form?
> 
> If you're using form_for -- and you didn't say if you were! -- then the 
> form is initialized from the supplied model object.



Ok ... here's the code

---------------------------------------------

\zauth\app\views\users\new.html.erb
<fieldset>
<legend>Signup for eMeantime Membership</legend>
<%= error_messages_for :user %>

 <% form_for :user, :url => users_path  do |f| -%>

  <p><label for="login">Login:</label><br/>
  <%= f.text_field :login %> <br/>
  <cite>Ex., aedenfield</cite>

  <p><label for="email">Email:</label><br/>
  <%= debugger; '' -%>
  <%= f.text_field :email %><br/>
  <cite>Ex., [email protected]. A valid email is required for an active 
account.</cite>

  <p><label for="password">Password:</label><br/>
  <%= f.password_field :password %><br/>
  <cite> Enter the password that is between 4 and 40 characters in 
length.</cite>

  <p><label for="password_confirmation">Confirm Password:</label><br/>
  <%= f.password_field :password_confirmation %><br/>
  <cite>Enter the same password as above.</cite>

  <p><%= submit_tag 'Sign up' %></p>
<% end -%>

</fieldset>


------------------------------------------------------------


\zauth\app\controllers\users_controller.rb

class UsersController < ApplicationController
  # Protect these actions behind an admin login
  # before_filter :admin_required, :only => [:suspend, :unsuspend, 
:destroy, :purge]
  before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, 
:purge]


  # render new.rhtml
  def new
  end

  def create
    puts at_file_line_msg(__FILE__, __LINE__)
    cookies.delete :auth_token
    # protects against session fixation attacks, wreaks havoc with
    # request forgery protection.
    # uncomment at your own risk
    # reset_session
    @user = User.new(params[:user])
    raise ActiveRecord::RecordInvalid.new(@user) unless @user.valid?
    @user.register!

    flash[:notice] = "Thanks for signing up!"
  rescue ActiveRecord::RecordInvalid
    render :action => 'new'
  end

  def activate
    self.current_user = params[:activation_code].blank? ? :false : 
User.find_by_activation_code(params[:activation_code])
    if logged_in? && !current_user.active?
      current_user.activate!
      flash[:notice] = "Signup complete!"
    end
    redirect_back_or_default('/')
  end

  def suspend
    @user.suspend!
    redirect_to users_path
  end

  def unsuspend
    @user.unsuspend!
    redirect_to users_path
  end

  def destroy
    @user.delete!
    redirect_to users_path
  end

  def purge
    @user.destroy
    redirect_to users_path
  end

  def change_password
    return unless request.post?
    if User.authenticate(current_user.login, params[:old_password])
      if ((params[:password] == params[:password_confirmation]) && 
!params[:password_confirmation].blank?)
        current_user.password_confirmation = 
params[:password_confirmation]
        current_user.password = params[:password]

        if current_user.save
          flash[:notice] = "Password successfully updated"
          redirect_to profile_url(current_user.login)
        else
          flash[:alert] = "Password not changed"
        end

      else
        flash[:alert] = "New Password mismatch"
        @old_password = params[:old_password]
      end
    else
      flash[:alert] = "Old password incorrect"
    end
  end

  #gain email address
  def forgot_password
    return unless request.post?
    if @user = User.find_by_email(params[:user][:email])
      @user.forgot_password
      @user.save
      redirect_back_or_default('/')
      flash[:notice] = "A password reset link has been sent to your 
email address"
    else
      flash[:alert] = "Could not find a user with that email address"
    end
  end

  #reset password
  def reset_password
    @user = User.find_by_password_reset_code(params[:id])
    return if @user unless params[:user]

    if ((params[:user][:password] && 
params[:user][:password_confirmation]) && 
!params[:user][:password_confirmation].blank?)
      self.current_user = @user #for the next two lines to work
      current_user.password_confirmation = 
params[:user][:password_confirmation]
      current_user.password = params[:user][:password]
      @user.reset_password
      flash[:notice] = current_user.save ? "Password reset success." : 
"Password reset failed."
      redirect_back_or_default('/')
    else
      flash[:alert] = "Password mismatch"
    end
  end

protected
  def find_user
    @user = User.find(params[:id])
  end
end


------------------------------------------------------------


I apologize for the length of the code but since I am lost as to where 
in the model the code initializes the form ... I provided everything.


The fields that seem to be inappropriately initialized are the fields 
associated with :email (definitely) and :password (maybe).

The :password field has big dots in it ... and it _may_ be initialized 
... I can't tell.
-- 
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