Sure Kenny! (and thanks),

I have a login page, where the user (I call an 'Associate')
authenticates to. They can also, from that page, update their
Associate's record (with contact info, etc.). ADDITIONALLY, I am
letting administrators do a list, via AS, of Associates, and edit /
create from there (thus, I have the session variable 'fromlogin' to
determine where to route to, i.e., where they are coming from. If
fromlogin==0, I know it is the administrator in AS editing the record.

Here is my controller:

class AssociatesController < ApplicationController
  before_filter :require_associate, :only =>
[:index, :show, :list, :edit, :update, :delete, :destroy, :search]
  before_filter :setforlist, :only => [:index, :show, :list]

  active_scaffold :associate do |config|
      config.label = "Associates"
      config.create.columns =
[:username, :email, :prefix, :firstname, :middlename, :lastname, :street1, 
:street2, :city,  :state, :postalcode, :country,  :phonework, :phonehome, 
:phonecell, :phonefax,  :phoneother, :jobtitle, :organization,  :startdate, 
:dob,  :ssno,  :maritalstatus, :password, :custom1, :custom2,  :custom3, 
:custom4,  :branch, :notes ]
      config.update.columns =
[:username, :email, :prefix, :firstname, :middlename, :lastname, :street1, 
:street2, :city,  :state, :postalcode, :country,  :phonework, :phonehome, 
:phonecell, :phonefax,  :phoneother, :jobtitle, :organization,  :startdate, 
:dob,  :ssno,  :maritalstatus, :password, :custom1, :custom2,  :custom3, 
:custom4,  :branch, :notes ]
      config.list.columns  =
[:lastname, :firstname, :username, :email, :branch]
      #list.columns.exclude :comments
      config.columns[:state].form_ui = :usa_state
      config.columns[:country].form_ui = :country
      list.sorting = {:lastname => 'ASC'}
      #columns[:phone].label = "Phone #"
      columns[:phonework].description = "(Format: ###-###-####)"
      columns[:phonehome].description = "(Format: ###-###-####)"
      columns[:phonecell].description = "(Format: ###-###-####)"
      columns[:phonefax].description = "(Format: ###-###-####)"
      config.actions.exclude :show #, :delete
      config.actions.swap :search, :live_search

    end

    def setforlist
      session['fromlogin']=0
    end

          def new
              @associate = Associate.new
              render :action => 'new', :layout => 'other_layout'
          end

          def create
            @associate = Associate.new(params[:associate])
            @associate.startdate = Date.today
            if @associate.save
              flash[:notice] = "Registration successful."
              redirect_to root_url
            else
              #render :action => 'new'
              render :action => 'new', :layout => 'other_layout'
            end
          end

          def edit
            @associate = current_associate
            render :action => 'edit', :layout => 'other_layout'
            _get_states #forces state to be set when edit div
displayed
          end

          def update
            @associate = current_associate #Associate.find(params[:id])
#
            if @associate.update_attributes(params[:associate])
              flash[:notice] = "Successfully updated profile."
              #puts session['fromlogin']
              if(session['fromlogin']!= nil && session['fromlogin']
==1)
                  redirect_to root_url
              end
              session['fromlogin']=0
            else
              render :action => 'edit', :layout =>
'other_layout'
              #render :action => 'edit'
            end
          end

  def do_destroy
      associate = Associate.find(params[:id])
      self.successful = associate.update_attributes(:deleted => -1)
    end

   def _get_states
     q = params[:country]
     # puts "******************"
     if(q==nil)
       @associate = current_associate
       [email protected]
     end
     #puts q
     if(q!=Carmen.default_country)
        q1 = q.gsub("_", " ")
        if(q1!=q && q1!=nil)
            q = q1.titleize #q1.split(' ').map {|w| w.capitalize }.join
(' ')
        else
            q.capitalize!
        end
        q = Carmen::country_code(q)
     end
     #puts q
     #puts Carmen.default_country
     #puts "******************"
    @states =  Carmen::states(q)
   end
end


(p.s. I am using Authologic for authentication)

Here is my login view:
<% title "Login" %>

<% form_for @associate_session do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :username %><br />
    <%= f.text_field :username %>
  </p>
  <p>
    <%= f.label :password %><br />
    <%= f.password_field :password %>
  </p>
  <br />
  <%= f.check_box :remember_me %>
  <%= f.label :remember_me %><br />
  <br />
  <% session['fromlogin'] = 1 %>
  <p><%= f.submit "Submit" %></p>
<% end %>


Here is my Associates partial that gets called on new or edit:

<% form_for @associate do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :username %><br />
    <%= f.text_field :username %>
  </p>
  <p>
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </p>
  <p>
    <%= f.label :password %><br />
    <%= f.password_field :password %>
  </p>
  <p>
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation %>
  </p>
  <p>
    <%= f.label :prefix %><br />
    <%= f.select( "prefix", [
    ["Mr." , "Mr."],
    ["Mrs.","Mrs."],
    ["Miss", "Miss"],
    ["Ms." ,"Ms."],
    ["Dr." , "Dr."],
    ["Hon.","Hon."],
    ["Fr. ", "Fr."]], {:include_blank => true})
      %>
  </p>
  <p>
     <%= f.label :firstname %><br />
     <%= f.text_field :firstname %>
  </p>
  <p>
     <%= f.label :middlename %><br />
     <%= f.text_field :middlename %>
  </p>
  <p>
     <%= f.label :lastame %><br />
     <%= f.text_field :lastname %>
  </p>
  <p>
     <%= f.label :street1 %><br />
     <%= f.text_field :street1 %>
  </p>
  <p>
     <%= f.label :street2 %><br />
     <%= f.text_field :street2 %>
  </p>
  <p>
     <%= f.label :city %><br />
     <%= f.text_field :city %>
  </p>
  <p>
    <%= f.label :state %><br />
  <select id="state" name="state">
    <option></option>
  <%= render :partial => 'get_states' %>
  </select>
  </p>
  <p>
      <%= f.label :postalcode %><br />
      <%= f.text_field :postalcode %>
   </p>
  <p>
  <%= f.label :country %><br />
  <% @associate = current_associate %>
  <% @associate == nil || @associate.country == nil ? s =
Carmen.default_country : s = @associate.country.strip %>
   <%= f.country_select :country, s, {},
    {
      :onChange => remote_function( :url => { :action =>
'_get_states' }, :update => "state", :with => "'country=' +value")
    } %>
   </p>




    <!--
 :phonework, :phonehome, :phonecell, :phonefax,  :phoneother, :jobtitle, 
:organization,  :startdate, :dob,  :ssno,  :maritalstatus, :password, :custom1, 
:custom2,  :custom3, :custom4,  :branch, :notes ]
    -->

  <p>
    <%= f.label :notes %><br />
    <%= f.text_area :notes %>
  </p>

  <p><%= f.submit "Submit" %></p>


<% end %>


Thanks so much! -Janna B.

On May 28, 9:08 am, Kenny Ortmann <[email protected]> wrote:
> Can I see your controller and your override?
>
> AS does a lot to make the row collapse happen so I need to see what you are
> doing to tell you where to start.
>
> Kenny
>
> On Thu, May 28, 2009 at 8:05 AM, JannaB <[email protected]> wrote:
>
> > I have one model (of many in a rails app that invoke AS) that I have
> > to put my own form in for editing. When that form is submitted --
> > either on a new or update, I want it to behave exactly as it would if
> > it were the typical AS edit or new.
>
> > What must I do to accomplish this? I have the form in place, it gets
> > called up properly, but I dont know what AS does after the submit
> > button is hit, to make the edited row collapse into the list view.
> > Thanks, Janna B.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to