boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-03 05:04 UTC
.rjs update only showing un-rendered javascript
When it first renders, it looks great, but when I drag an item to a
different location in inlist, it updates with javascript that hasnt
been rendered... I''m totally out of ideas on how to fix this. I just
want an ajax call to update the table... If i''m going at this the
wrong way please let me know!
Check it out at: www.boxhaxor.com/picture_management
The drag and drop list updates like i think it should, but the list
above just renders garbage!
The code:
rjs file
page.replace_html ''table'',render(:partial =>
"table", :object =>
@pictures)
controller
...
def updateinlist(updatethis)
if updatethis == nil
redirect_to :action => :list#_index("updateinlist::updatethis list
empty!")
end
@updateinlist = updatethis#params[:inlist]
i = 1
@updateinlist.each do |theid|
@picture = Picture.find(theid)
@picture.position = i
@picture.save
i = i+1
end
#updatetable
#render :partial => ''picture'', :collection =>
Picture.find(:all)
end
def updatetable
@par = params[:inlist]
if @par == nil
redirect_to_index("An error has occured!")
end
@pictures = Picture.find(:all)
updateinlist(@par)
#render :partial => ''table'', :collection =>
Picture.find(:all)
end
...
view
(this is what i want to update when a change happens in the drag n
drop list below)
<div id="table">
<%= render(:partial => "table", :object => @pictures) %>
</div>
...
(this is the list that is drag and drop)
<div style="height:200px;">
<div id="inlist"
style="height:150px;width:200px;float:left;">
<h2> Order of List</h2>
<% for picture in @ordered_pictures %>
<% if picture.position >= 0 -%>
<div id="item_<%= picture.id %>"
class="listitem">
<%= picture.id %> <%= picture.title
%> <%picture.photographer %>
</div>
<% end -%>
<% end %>
</div>
...
<%= sortable_element ''inlist'',
:update => ''inlist'',
:complete => visual_effect(:highlight, ''inlist''),
:url => { :action => "updatenotlist" } %>
...
<script type="text/javascript">
Sortable.create("inlist", {tag:''div'',dropOnEmpty:
true, containment:
["inlist","notlist"],constraint:false,
onUpdate:function(){new
Ajax.Updater(''table'',
''/picture_management/updatetable'',
{asynchronous:true, onComplete:function(equest){new
Effect.Highlight("inlist",{});},
parameters:Sortable.serialize("inlist")})}});
</script>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
You need to explicitly set evalScripts to true for the Ajax.Updater call - that''s why you''regetting JS code right now. I''ll let more expert users decide if replacing a whole table when a Sortable element is moved is correct usage.. --Matt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
you shouldn''t specify the :update option in the sortable_element when usign RJS. EITHER: set the :update option and render back pure HTML from the server to the client (behind the scenes: evalScripts = false) OR: do NOT set the :update option, and render back Javascript (e.g. with RJS) (behind the scenes: evalScripts = true) On 3 Feb., 23:53, "Matt Jones" <mdj.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You need to explicitly set evalScripts to true for the Ajax.Updater call - > that''s why you''regetting JS code right now. > > I''ll let more expert users decide if replacing a whole table when a Sortable > element is > moved is correct usage.. > > --Matt--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-04 16:45 UTC
Re: .rjs update only showing un-rendered javascript
I have changed the ajax call to:
Sortable.create("inlist", {tag:''div'',dropOnEmpty:
true, containment:
["inlist","notlist"],constraint:false,
onUpdate:function(){new
Ajax.Updater(''table'',
''/picture_management/updatetable'',
{asynchronous:true, evalScripts:true, onComplete:function(equest){new
Effect.Highlight("inlist",{});},
parameters:Sortable.serialize("inlist")})}});
and
<%= sortable_element ''inlist'',
:complete => visual_effect(:highlight, ''inlist''),
:url => { :action => "updatenotlist" } %>
However, it still gives me unrendered javascript. I have also tried
to changing the evalScripts:false, and had the update in there...
Same result.
When you link or submit a form to do something like this normally you
have to use a link_to_remote or form_remote_tag, is there a
sortable_element that is the equivalent to one of those?
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-04 16:51 UTC
Re: .rjs update only showing un-rendered javascript
I have removed the update and changed the evalScripts:false, same
effect. I also tried to evalScripts:false with the update and was
still getting javascript.
Sortable.create("inlist", {tag:''div'',dropOnEmpty:
true, containment:
["inlist","notlist"],constraint:false,
onUpdate:function(){new
Ajax.Updater(''table'',
''/picture_management/updatetable'',
{asynchronous:true, evalScripts:true, onComplete:function(equest){new
Effect.Highlight("inlist",{});},
parameters:Sortable.serialize("inlist")})}});
&
<%= sortable_element ''inlist'',
:complete => visual_effect(:highlight, ''inlist''),
:url => { :action => "updatenotlist" } %>
With linking to stuff with ajax you normally use link_to_remote or
form_remote_tag, is there a way to do that with sortable_element?
Thanks!
www.boxhaxor.com/picture_management
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-04 16:54 UTC
Re: .rjs update only showing un-rendered javascript
Drag and drop one of the items under "Order of list" to see it fail... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 4, 2008 10:45 AM, boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have changed the ajax call to: > Sortable.create("inlist", {tag:''div'',dropOnEmpty: true, containment: > ["inlist","notlist"],constraint:false, onUpdate:function(){new > Ajax.Updater(''table'', ''/picture_management/updatetable'', > {asynchronous:true, evalScripts:true, onComplete:function(equest){new > Effect.Highlight("inlist",{});}, > parameters:Sortable.serialize("inlist")})}});The first parameter to the Ajax.Updater should be an empty string if you don''t want it to update anything on the page. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-04 17:49 UTC
Re: .rjs update only showing un-rendered javascript
Interesting, now i''m not getting the updated data, however i''m not getting crap. What is the timing like? Does the .rjs call happen before the controller? That would explain why i''m not getting the updated information... If so, how do you update the database info then send the update? Sorry for all the newbie questions. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
boxhaxor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-04 18:27 UTC
Re: .rjs update only showing un-rendered javascript
Never mind! Thanks for all the help! Just had to reorder some statements in my controller! @pictures = Picture.find(:all) updateinlist(@par) to updateinlist(@par) @pictures = Picture.find(:all) I was populating the object before the the changes had been made! Whoops! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---