Ok, but she's a BIG baby:

class AssociatesController < ApplicationController
  #before_filter :require_no_user, :only => [:new, :create]
  #before_filter :require_user, :only => :destroy
  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, :phone1, :phone2, :phone3, 
: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, :phone1, :phone2, :phone3, 
: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[:phone1].description = "(Format: ###-###-####)"
        columns[:phone2].description = "(Format: ###-###-####)"
        columns[:phone3].description = "(Format: ###-###-####)"
        config.actions.exclude :show #, :delete
      config.actions.swap :search, :live_search
    end

    def update_respond_to_html
      puts "yakkkk"
      puts params[:iframe]
      if params[:iframe]=='true' # was this an iframe post ?
        responds_to_parent do
          if successful?
            render :action => 'on_update.js'
          else
            render :action => 'form_messages_on_update.js'
          end
        end
      else # just a regular post
        if successful?
          flash[:info] = as_(:updated_model, :model =>
@record.to_label)
          return_to_main
        else
            render(:action => 'update')
        end
      end
    end

    def setforlist
      session['fromlogin']=0
    end

    def new
        get_states #forces state to be set when edit div displayed
        @associate = Associate.new
        render :action => 'new', :layout =>
'other_layout'
    end

    def create
      params[:associate][:state]=params['state']
      @associate = Associate.new(params[:associate])
      set_branch_code
      if @associate.save
        if(session['fromlogin']!= nil && session['fromlogin']
==1)
          flash[:notice] = "Registration successful."
          redirect_to root_url
         end
         session['fromlogin']=0
         do_list    #re-sort, etc from active_scaffold/lib/
active_scaffold/actions/list.do_list
         render(:action => 'list', :id => nil)
      else
        #render :action => 'new'
        render :action => 'new', :layout => 'other_layout'
      end
    end

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

    def update
      @associate=the_associate
      set_branch_code
      params[:associate][:state]=params['state']
      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
            session['fromlogin']=0
            return
        end
        session['fromlogin']=0
        do_list    #re-sort, etc from active_scaffold/lib/
active_scaffold/actions/list.do_list
        #render(:action => 'list', :id => nil)
        redirect_to   "/associates/"
      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 the_associate
      if(session['fromlogin']!= nil && session['fromlogin']==1)
          return current_associate
        else
          if params[:id]=="current"
              return current_associate
          else
              return Associate.find(params[:id])
          end
        end
    end

    def _get_states
      @associate = the_associate
      get_states
    end

   def get_states
     q = params[:country]
     #puts "******************"
      if(q==nil)
        @associate = the_associate
        if(@associate==nil)
          q=Carmen.default_country
        else
          [email protected]
        end
      end
      #puts q
      if(q!=Carmen.default_country)
         q1 = q.gsub("_", " ")
         q.capitalize!
         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 Carmen.default_country
      #puts q
      #puts (Carmen::states(q)).length
      #puts "******************"
     @states =  Carmen::states(q)
   end

   def set_branch_code
     if @associate.branch==nil
       @associate.branch="pending"
     else
       if(params['xbranch']!=nil)
         if @associate.lbranch==""
           @associate.branch=(params['xbranch']).to_s
         else
           @associate.branch=(@associate.lbranch).to_s + (params
['xbranch']).to_s
         end
       end
     end
   end

end


On Jun 5, 3:34 am, "Sergio Cambra .:: entreCables S.L. ::."
<[email protected]> wrote:
> On Jueves, 4 de Junio de 2009 17:45:21 JannaB escribió:
>
> > Hmmm, I have....and it is never getting  invoked?
>
> Please, post your controller
>
>
>
>
>
> > On Jun 4, 11:21 am, "Sergio Cambra .:: entreCables S.L. ::."
>
> > <[email protected]> wrote:
> > > On Jueves, 4 de Junio de 2009 16:08:30 JannaB escribió:
> > > > Can I override that in my controller? I only need it to work with one
> > > > controller/model/view slice, not the whole application. -JannaB
>
> > > Yes you must override it in your controller. Put it below active_scaffold
> > > configure block
>
> > > > On Jun 4, 5:56 am, "Sergio Cambra .:: entreCables S.L. ::."
>
> > > > <[email protected]> wrote:
> > > > > On Miércoles, 3 de Junio de 2009 22:47:43 JannaB escribió:
> > > > > > The problem is that it occurs in
>
> > > > > > Associates.update
>
> > > > > > Which reroutes me back to the associates table. There has to be a
> > > > > > way in Associates.update that I can have it do nothing with the
> > > > > > view?
>
> > > > > You must to override update_respond_to_html in order to redirect to
> > > > > request.referer for example.
>
> > > > > > On Jun 3, 3:05 pm, JannaB <[email protected]> wrote:
> > > > > > > updating Segio (and thank's for that textarea fixup!) -Janna
>
> > > > > > > On Jun 3, 9:53 am, "Sergio Cambra .:: entreCables S.L. ::."
>
> > > > > > > <[email protected]> wrote:
> > > > > > > > On Miércoles, 3 de Junio de 2009 14:32:39 JannaB escribió:
> > > > > > > > > I have a partial, in my main layout, application.html.erb,
> > > > > > > > > the partial appears as follows:
>
> > > > > > > > > <% form_for current_associate, :html => {:name =>
> > > > > > > > > 'whereaboutsform'} do |f| %>
> > > > > > > > >     <%= f.label :inoutexplanation,
> > > > > > > > > current_associate.nice_to_s << " whereabouts:" %><br />
> > > > > > > > >     <%= f.text_field :inoutexplanation %>
> > > > > > > > >    <%= f.submit "Submit" %>
> > > > > > > > > <% end %>
>
> > > > > > > > > The partial uses my associates table. This partial exists in
> > > > > > > > > a div at the top of all pages, regardless of what tale is
> > > > > > > > > presently being displayed by AS. However, when someone clicks
> > > > > > > > > "Submit", the table being displayed then reverts to the
> > > > > > > > > associates table, in list view.
>
> > > > > > > > > What would be a clean way (from an AS perspective) to prevent
> > > > > > > > > this? Thanks. -Janna B.
>
> > > > > > > > Is that form creating or updating an associate?
>
> > > > > > > > --
> > > > > > > > Sergio Cambra .:: entreCables S.L. ::.
> > > > > > > > Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
> > > > > > > > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>
> > > > > --
> > > > > Sergio Cambra .:: entreCables S.L. ::.
> > > > > Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
> > > > > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>
> > > --
> > > Sergio Cambra .:: entreCables S.L. ::.
> > > Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
> > > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>
> --
> Sergio Cambra .:: entreCables S.L. ::.
> Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
> T) 902 021 404 F) 976 52 98 07 E) [email protected]
--~--~---------~--~----~------------~-------~--~----~
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