Problem updating a row inside a list

80 views
Skip to first unread message

Jack

unread,
Apr 3, 2007, 5:40:21 PM4/3/07
to ActiveScaffold : Ruby on Rails plugin
Hello,

I'm trying to update a row inside an active scaffold list from an
action link attached to a column. I think I'm awfully close, but I
can't get the row to update without adding a yellow bar to the list.

The table in question has a column named 'active', which determines
whether a record is visible from the front-side application. I want
the user to click the active field in active scaffold to toggle it on
or off, and have the appropriate row update with the new active
value. I can toggle the active field, but I can't get the display to
refresh without the extra line.

Here's the controller code:

class RemsitesController < ApplicationController
active_scaffold :remsite do |config|
config.list.columns = [:active, :name, :ident]
config.columns[:active].set_link 'Toggle', :action =>
'toggle_active', :position => :replace
end

# toggle active flag
def toggle_active
@remsite = Remsite.find(params[:id])
@remsite.active = @remsite.active? ? false : true
@remsite.save

# redraw just the line in question
render :partial => 'list_record', :locals => {:record => @remsite}
end

end

This controller does what I need; however, it adds a yellow bar with a
close button above the record. I'd like to avoid the yellow bar.
I've tried :position => :replace, :position => false, :position
=> :false, all with the same results. I tried rendering the row
through RJS and got a page full of javascript code. Can someone help
me find the magic incantation to make this work?

Thanks,
Jack

Lance Ivy

unread,
Apr 3, 2007, 7:33:48 PM4/3/07
to actives...@googlegroups.com
Have you already tried the combination of :position => false + an RJS response? This is the technique that the Delete module uses. See lib/config/delete.rb, lib/actions/delete.rb, and frontends/default/views/destroy.rjs for an example.

Lemme know if that doesn't work and I'll try and reproduce it. :)

-Lance

Jack

unread,
Apr 4, 2007, 3:30:04 PM4/4/07
to ActiveScaffold : Ruby on Rails plugin
It turns out there's a bug in the set_link method, it completely
ignores :position => false

The fix is pretty simple; in lib/data_structures/column.rb, line 73,
change:

options[:position] ||= :after

to:

options[:position] = :after unless options.has_key?(:position)

The controller now looks like:

class RemsitesController < ApplicationController
active_scaffold :remsite do |config|
config.list.columns = [:active, :name, :ident]
config.columns[:active].set_link 'Toggle', :action =>

'toggle_active', :position => false
end

# toggle active flag
def toggle_active
@remsite = Remsite.find(params[:id])
@remsite.active = @remsite.active? ? false : true
@remsite.save

end
end

The toggle_active.rjs view looks like:

page.replace_html element_row_id(:action => 'list', :id =>
params[:id]), :partial => 'list_record_element', :locals => {:record
=> @remsite}
page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');"

I had to create a _list_record_element.rhtml partial to redraw the
row. _list_record.rhtml includes the <tr> tags which throws off the
display, _list_record_element.rhtml is just _list_record.rhtml without
the <tr> tags. _list_record_element.rhtml is in views/
active_scaffold_overrides and looks like:

<% url_options = params_for(:action => :list, :id => record.id) -%>

<% active_scaffold_config.list.columns.each do |column| %>
<% column_value = render_column(record, column) -%>

<td class="<%= column_class(column, column_value) %>" >
<% if column.link -%>
<% column.link.label = column_value %>
<%= render_action_link(column.link, url_options) %>
<% else -%>
<%= column_value %>
<% end -%>
</td>
<% end -%>
<% if active_scaffold_config.action_links.any? {|link| link.type
== :record } -%>
<td class="actions">
<%= render :partial => 'list_actions', :locals => {:record =>
record, :url_options => url_options} %>
</td>
<% end -%>
<% target_id = element_row_id(:action => :list, :id => record.id) -%>
<script type="text/javascript">
actions = new ActiveScaffold.Actions.Record(
$$('#<%= target_id -%> a.action'),
$('<%= target_id -%>'),
$('<%= loading_indicator_id(:action => :record, :id => record.id) -
%>'),
{refresh_url: '<%= url_for params_for(:action => :row, :id =>
record.id, :_method => :get, :escape => false) -%>'}
);
</script>

Lance Ivy

unread,
Apr 4, 2007, 4:42:18 PM4/4/07
to actives...@googlegroups.com
Awesome, thanks Jack. I'm patching set_link right now.

Also, try switching 'page.replace_html' to 'page.replace' and 'list_record_element' back to just 'list_record'.

dimitris

unread,
Apr 24, 2007, 9:03:51 AM4/24/07
to ActiveScaffold : Ruby on Rails plugin
Hi,

Is setting :position => false + rjs still the way to go to update a
record row after manipulating it with an action link, or is there an
easier way?

Thanks in advance

Lance Ivy

unread,
Apr 24, 2007, 11:31:34 AM4/24/07
to actives...@googlegroups.com
Yep, that's the way to go still. You could make a request in the tracker for an official way ...
Message has been deleted

dimitris

unread,
Apr 24, 2007, 1:51:59 PM4/24/07
to ActiveScaffold : Ruby on Rails plugin
Hi Lance, thanks for your quick reply

I followed the instructions in
http://groups.google.com/group/activescaffold/browse_thread/thread/60b264a79a0ade53/4a58624e90ad92f7?lnk=gst&q=update&rnum=4#4a58624e90ad92f7
and noticed a few quirks:

For an article model with a published attribute (boolean), and an
action link (config.action_links.add 'publish', :label =>
'Publicera', :type => :record, :parameters => {:action =>
'publish'}, :inline => true, :position => :replace) the output is:

1. The rjs code:
page.replace_html "articles-list-#{params[:id]}-row", :partial =>
'list_record', :locals => { :record => @article }


page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');"

2. The controller correctly updates the published attribute for the
record
3. the row does not get updated, and there is an rjs error instead:
try { Element.update("articles-list-1-row", "\n
\n \n \n \n Huvudnyhet\n \n \n \n \n true\n \n \n \n \n Nyheter\n \n
\n
\r\n \r\n \r\n \"loading\r\n \r\n \r\n \r\n \r\n Publicera\r\n \r\n \r
\n \r\n \r\n Edit\r\n \r\n \r\n \r\n \r\n Delete\r\n \r\n \r\n \r\n
\r\n Show\r\n \r\n \r\n
\r\n
\n \n
\n\n\n"); ActiveScaffold.stripe('articles-tbody'); } catch (e)
{ alert('RJS error:\n\n' + e.toString());
alert('Element.update(\"articles-list-1--row\", \"\\n\\n \\n \\n \\n
Huvudnyhet\\n \\n \\n \\n \\n true\\n \\n \\n \\n \\n Nyheter\\n \\n
\\n
\\r\\n \\r\\n \\r\\n \\\"loading\\r\\n \\r\\n \\r\\n \\r\\n \\r\\n
Publicera\\r\\n \\r\\n \\r\\n \\r\\n \\r\\n Edit\\r\\n \\r\\n \\r\\n \
\r\\n \\r\\n Delete\\r\\n \\r\\n \\r\\n \\r\\n \\r\\n Show\\r\\n \\r\
\n \\r\\n
\\r\\n
\\n \\n
\\n\\n\\n\");\nActiveScaffold.stripe(\'articles-tbody\');'); throw e }
3. reading the source, I noticed that the record rows have an id that
looks like articles-list-1--row, a double dash after the id, which may
be wrong?

Changing the rjs to replace instead of replace_html and/or changing
the id for the row to contain two dashes instead of one makes no
significant difference. Can I debug this further to help you see
what's wrong?

Thanks in advance,

/Dimitris


On Apr 24, 6:31 pm, "Lance Ivy" <l...@cainlevy.net> wrote:
> Yep, that's the way to go still. You could make a request in the tracker for
> an official way ...
>

Lance Ivy

unread,
Apr 30, 2007, 2:13:57 PM4/30/07
to actives...@googlegroups.com
Hmm, what's the actual RJS error? Also, what browser are you using?

Also, you see how the bit you pasted in step #3 is split into two halves? The first half is the attempt at actually doing something, and the second half is the alert dialog in case something goes wrong. Well the double dash only exists in the second half; in the first it's normal.

On 4/24/07, dimitris <jazz...@gmail.com> wrote:

jai...@gmail.com

unread,
Jun 9, 2007, 7:57:01 AM6/9/07
to ActiveScaffold : Ruby on Rails plugin
I've got exactly the same error....


On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:
> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>

> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>

> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...

jai...@gmail.com

unread,
Jun 9, 2007, 7:57:23 AM6/9/07
to ActiveScaffold : Ruby on Rails plugin
I've got exactly the same error....


On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:

> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>

> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>

> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...

jai...@gmail.com

unread,
Jun 9, 2007, 7:58:19 AM6/9/07
to ActiveScaffold : Ruby on Rails plugin
I've got exactly the same error....


On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:

> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>

> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>

> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...

jai...@gmail.com

unread,
Jun 9, 2007, 8:11:54 AM6/9/07
to ActiveScaffold : Ruby on Rails plugin
The generated html code, in my case is (looks like javascript code is
not being interpreted):

tr class="inline-adapter">
<td style="background-image: none; background-color: transparent;"
colspan="99" class="inline-adapter-cell">
<div class="anular_pedido-view view">

<a href="" class="inline-adapter-close" title="close">Close</a>
try {
Element.update("privado__pedidos-list-7-row", "\n</div></td></tr><tr
\="" id="\&quot;privado__pedidos-list-7-row\&quot;"
class="\&quot;record">\n \n \n <td class="\&quot;referencia-
column" \="">\n 2007-06-08-000012\n </td>\n
\n \n <td class="\&quot;estado-column" \="">\n
ANULADO\n </td>\n \n \n <td
class="\&quot;fecha_creacion-column" \="">\n 06/08/2007
10:42 PM\n </td>\n \n \n <td
class="\&quot;fecha_actualizacion-column" \="">\n
06/08/2007 10:42 PM\n </td>\n \n \n <td
class="\&quot;User-column" \="">\n 12345\n </td>
\n \n \n <td class="\&quot;forma_pago-column" \="">
\n VISA/MASTERCARD\n </td>\n \n \n
<td class="\&quot;forma_envio-column" \="">\n RECOGER
\n </td>\n \n \n <td class="\&quot;pagado-column"
\="">\n NO\n </td>\n <td
class="\&quot;actions\&quot;">\n <table cellpadding="0"
cellspacing="0">\n <tbody><tr>\n <td class="\&quot;indicator-
container\&quot;">\n <img alt="\&quot;loading" indicator\=""
class="\&quot;loading-indicator\&quot;" id="\&quot;privado__pedidos-
record-7-loading-indicator\&quot;" src="%5C%22/images/active_scaffold/
default/indicator.gif?1181390088%5C%22" style="">\n </td>
\n <td>\n <a href="%5C%22/privado/pedidos/nested/
7?_method=get&amp;associations=Lineapedido%5C%22"
class="\&quot;nested" action\="" id="\&quot;privado__pedidos-nested-7-
link\&quot;" position="\&quot;after\&quot;">Ver productos</a> </
td>\n <td>\n <a href="%5C%22/privado/pedidos/
nested/7?_method=get&amp;associations=DireccionEntrega%5C%22"
class="\&quot;nested" action\="" id="\&quot;privado__pedidos-nested-7-
link\&quot;" position="\&quot;after\&quot;">Direccion</a> </td>
\n <td>\n <a href="%5C%22/privado/pedidos/
anular_pedido/7?_method=get%5C%22" class="\&quot;anular_pedido" action
\="" id="\&quot;privado__pedidos-anular_pedido-7-link\&quot;"
position="\&quot;replace\&quot;">Anular</a> </td>
\n <td>\n <a href="%5C%22/privado/pedidos/edit/7?
_method=get%5C%22" class="\&quot;edit" action\=""
id="\&quot;privado__pedidos-edit-7-link\&quot;"
position="\&quot;replace\&quot;">Edit</a> </td>\n
<td>\n <a href="%5C%22/privado/pedidos/destroy/7?_method=delete
%5C%22" class="\&quot;destroy" action\="" id="\&quot;privado__pedidos-
destroy-7-link\&quot;" onclick='\"return' confirm(="" are="" you=""
sure?="" );\="">Delete</a> </td>\n </tr>\n</tbody></table>
\n </td>\n </tr>\n\n\n");
ActiveScaffold.stripe('privado__pedidos-tbody');


} catch (e) { alert('RJS error:\n\n' + e.toString());

alert('Element.update(\"privado__pedidos-list-7-row\", \"\\n<tr \\\=""
id="\\\&quot;privado__pedidos-list-7-row\\\&quot;" class="\\
\&quot;record">\\n \\n \\n <td class="\\\&quot;referencia-
column" \\\="">\\n 2007-06-08-000012\\n </td>\
\n \\n \\n <td class="\\\&quot;estado-column" \\\="">\
\n ANULADO\\n </td>\\n \\n \\n <td
class="\\\&quot;fecha_creacion-column" \\\="">\\n
06/08/2007 10:42 PM\\n </td>\\n \\n \\n <td
class="\\\&quot;fecha_actualizacion-column" \\\="">\\n
06/08/2007 10:42 PM\\n </td>\\n \\n \\n <td
class="\\\&quot;User-column" \\\="">\\n 12345\\n
</td>\\n \\n \\n <td class="\\\&quot;forma_pago-column" \\
\="">\\n VISA/MASTERCARD\\n </td>\\n \\n
\\n <td class="\\\&quot;forma_envio-column" \\\="">\\n
RECOGER\\n </td>\\n \\n \\n <td class="\\
\&quot;pagado-column" \\\="">\\n NO\\n </td>\
\n <td class="\\\&quot;actions\\\&quot;">\\n <table
cellpadding="0" cellspacing="0">\\n <tbody><tr>\\n <td class="\\
\&quot;indicator-container\\\&quot;">\\n <img alt="\\
\&quot;loading" indicator\\\="" class="\\\&quot;loading-indicator\\
\&quot;" id="\\\&quot;privado__pedidos-record-7-loading-indicator\\
\&quot;" src="%5C%5C%5C%22/images/active_scaffold/default/
indicator.gif?1181390088%5C%5C%5C%22" style="">\\n </td>\
\n <td>\\n <a href="%5C%5C%5C%22/privado/pedidos/
nested/7?_method=get&amp;associations=Lineapedido%5C%5C%5C%22" class="\
\\&quot;nested" action\\\="" id="\\\&quot;privado__pedidos-nested-7-
link\\\&quot;" position="\\\&quot;after\\\&quot;">Ver productos</
a> </td>\\n <td>\\n <a href="%5C%5C%5C%22/
privado/pedidos/nested/7?_method=get&amp;associations=DireccionEntrega
%5C%5C%5C%22" class="\\\&quot;nested" action\\\="" id="\\
\&quot;privado__pedidos-nested-7-link\\\&quot;" position="\\
\&quot;after\\\&quot;">Direccion</a> </td>\\n <td>\
\n <a href="%5C%5C%5C%22/privado/pedidos/anular_pedido/7?
_method=get%5C%5C%5C%22" class="\\\&quot;anular_pedido" action\\\=""
id="\\\&quot;privado__pedidos-anular_pedido-7-link\\\&quot;"
position="\\\&quot;replace\\\&quot;">Anular</a> </td>\
\n <td>\\n <a href="%5C%5C%5C%22/privado/pedidos/
edit/7?_method=get%5C%5C%5C%22" class="\\\&quot;edit" action\\\=""
id="\\\&quot;privado__pedidos-edit-7-link\\\&quot;" position="\\
\&quot;replace\\\&quot;">Edit</a> </td>\\n <td>\
\n <a href="%5C%5C%5C%22/privado/pedidos/destroy/7?
_method=delete%5C%5C%5C%22" class="\\\&quot;destroy" action\\\="" id="\
\\&quot;privado__pedidos-destroy-7-link\\\&quot;" onclick='\\\"return'
confirm(\="" are="" you="" sure?\="" );\\\="">Delete</a> </td>\
\n </tr>\\n</tbody></table>\\n </td>\\n </tr>\\n\\n\\n\");
\nActiveScaffold.stripe(\'privado__pedidos-tbody\');'); throw e }


On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:

> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>

> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>

> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...

jai...@gmail.com

unread,
Jun 9, 2007, 8:54:34 AM6/9/07
to ActiveScaffold : Ruby on Rails plugin
Fixed, with :position=>false

> ...
>
> leer más »

Reply all
Reply to author
Forward
0 new messages