Daniel
2011-Jan-30 18:00 UTC
Design/Implementation question on record (de)activation and view state preserving
What I want to achieve:
I have a model which has records that can either be activated or
deactivated. I want to show these records in a view. Based on the
state of a checkbox, the view should show either all activated records
or all records. Furthermore I would like to add a link to dis/enable a
record. This link should somehow submit the state of the checkbox too,
because I need to refresh the view after changing a records state. I
would like to do all this in ajax. Here is what i got so far:
## index view
<%= check_box_tag :showDisabled, :showDisabled, false, {:onclick =>
remote_function(:method => :get, :url => { :action => "index"
}, :with
=> "''value=''+this.checked") } %>
<div id=store_table><%= render ''store_table''
%></div>
<div id="new_store_link"> <%= link_to :new_store,
new_store_path, :remote => true %> </div>
<div id="new_store_form"></div>
## store partial
<script type="text/javascript" charset="utf-8">
$$(''a[data-remote=true]'').each(function(a){
a.onclick = function(){a.setAttribute(''href'',
a.getAttribute(''href'') +
eval(a.getAttribute(''data-with'')))};
});
</script>
<tr>
<td><%= store.title %></td>
<td><%= store.location %></td>
<td><%= store.street %></td>
<td><%= store.houseNumber %></td>
<td><%= store.zipCode %></td>
<td><%= store.town %></td>
<td><%= store.handelsRegisterNummer %></td>
<td><%= store.taxIdentificationNumber %></td>
<td><%= link_to "PDF Template",
store.pdfTemplate(:original, false)
unless store.pdfTemplate_file_name.blank? %></td>
<td><%= link_to :edit, edit_store_path(store), :remote => true
%></
td>
<td>
<%= link_to :deactivate, deactivate_store_path(store), {:remote =>
true, ''data-with'' =>
"'',value=>''+$(''showDisabled'').checked"}
unless
store.deactivated? %>
<%= link_to :activate, activate_store_path(store), :remote => true
unless store.activated? %>
</td>
</tr>
So, i got a working checkbox which refreshes the page through my store
partial. What isn''t working yet, are the links with included checkbox
state. I''m not sure if my checkbox is the best way to do this, so
I''m
open for suggestions :)
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.