Hi all,
Being a beginner in Ruby on Rails, I face issues with Drag & Drop.
Would you please give a simple working complete example for Drag and
Drop (with 2 lists)?
Or please find the below snippet and please help me find a solution.
Scenario:
Two draggable and droppable lists. Any item from one list should be
dropped to the other.
Note: Relevant code snippet is given below.
Issue:
While dropping, the already existing items get replaced by the dropped
one.
Reason would be – When the update_sel action is called, @selected is not
getting fetched with the old values (say, Project.find(:all, :conditions
=> "id <= 4")).
Solution:
A solved method or an entirely new method for drag & drop will do.
I prefer a new complete drag and drop method to the solved code of the
same.
Tip on the look and feel enhancement will also be very helpful.
A prompt response would be appreciated.
Code Snippet:
#Controller
before_filter :get_projects, :only => [:update_all, :update_sel]
def update_all
render :partial =>"allproj", :object => @available
end
def update_sel
#@selected.push Project.find(:all, :conditions => "id = " +
params[:id]) #This gets error - but this needed
@selected = Project.find(:all, :conditions => "id = " +
params[:id])
render :partial =>"selected", :object => @selected
end
private
def get_projects
@projects = Project.find(:all)
@available = Project.find(:all)
@selected = Project.find(:all, :conditions => "id <= 4")
#For the
time being - later another table used
end
#View
#index.rhtml
<div id="all_proj" style="border:1px solid;">
<%= render :partial =>"allproj", :object =>
@available %>
</div>
<br />
<h5>Selected Projects</h5>
<div id="sel_proj" style="border:1px solid;">
<%= render :partial =>"selected", :object =>
@selected %>
</div>
<%= drop_receiving_element("all_proj",
:accept => ''sel_item'',
:url => { :action => "update_all"},
:loading => visual_effect(:highlight),
:complete => visual_effect(:fade),
:update => ''all_proj'') %>
<%= drop_receiving_element("sel_proj",
:accept => ''all_item'',
:url => { :action => "update_sel"},
:with => "''id='' +
encodeURIComponent(element.id)",
:loading => visual_effect(:highlight),
:update => ''sel_proj'') %>
#_allproj.rhtml
<ul>
<% allproj.each do |project| %>
<% domid = "#{project.id}" %>
<li class="all_item" id=''<%= domid
%>''
style="cursor:move;"><%=project.proj_name %>
<%= draggable_element(domid, :revert => true) %>
</li>
<% end %>
</ul>
#_selected.rhtml
<ul>
<% selected.each do |project| %>
<% domid = "#{project.id}" %>
<li class="sel_item" id=''<%= domid
%>''
style="cursor:move;"><%=project.proj_name %>
<%= draggable_element(domid, :revert => true) %>
</li>
<% end %>
</ul>
Thanks & regards,
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---