On Viernes, 18 de Septiembre de 2009 23:36:09 alexp escribió:
> Hi all
>
> I just cant work this out, can somebody please help me out.  I'm not
> doing this for any commercial benefit just for my own learning curve
> but I need to know where to start
>
> Ebi posted some useful pointers but I cant get this right, Serge also
> helps in the post
>
> 1. I cant seem to get inplace_edit to work - I found a plugin but its
> not working well, most of the links I find are dead and I'm not sure
> where to find it.  Any links would help

http://github.com/rails/in_place_editing/tree/master

>
> 2. I'd like to create a select box in list view for an associated
> model so that at first it displays the text, then I click the text to
> get a drop down select box and on change save the record, I normally
> get "Create new" in place for a record when the assosicated field in
> the associated model in blank, I'd like to replace that with the
> select box instead.

First you should get the select box in your list view, then add the onchange 
event to sve the record with AJAX. At last, you can hide it and add a link 
with an onclick event to show the select box, after saving you will need to 
hide the select box and update the link.

For example, if you have models Players and Team, where a player belongs to 
team. Add to players controller and helper:

# PlayersHelper
  def team_column(record)
    @record = record # active_scaffold_input_select needs @record
    column = active_scaffold_config.columns[:team]
    id_options = {:id => record.id.to_s, :action => 'update_column', :name => 
column.name} # update_column will replace html for this element
    script = remote_function(:method => 'POST', :url => {:controller => 
params_for[:controller], :action => "update_column", :id => record.id.to_s, 
:eid => params[:eid]}, :with => "'column=#{column.name}&value='+this.value")
    content_tag :span, (record.team.try(:to_label) || 'select one') + 
active_scaffold_input_select(column, 
active_scaffold_input_options(column).merge({:onchange => script})), :id => 
element_cell_id(id_options)
  end

# PlayersController

active_scaffold do |config|
  [...]
  config.columns[:team].clear_link
end

def do_update_column
    old_column = params[:column]
    params[:column] = 
active_scaffold_config.columns[params[:column]].association.try(:primary_key_name)
 
|| old_column # inplace_edit in associations send the id
    super
    params[:column] = old_column        
end

>
> My level of understanding AS is growing, but I am loosing clarity on
> the best way to do this - I have lots of areas I'd like to use this -
> and sure others would benefit from this, so could anybody point me in
> the right direction, I am quite a novice in programming in this area.
>
> Thank you all for any help
>
>
> 
-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 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