I am new to this and need some help DRYing this view code: <div style="float: left;"> <h3>drop task name</h3> <ul>Projects <% for project in @projects %> <% project_id = "project_#{project.id}" %> <li id="<%= project_id %>" class="project" style="background-color: #CCC; margin: 0 20px 2px 0;"> <%=h project.name %> </li> <% #TODO need to DRY up the drop_receiving_element, perhaps with a helper%> <%= drop_receiving_element( project_id, # The id of the receiving element :accept => "task_name", # The CSS class of the dropped element #The action to call (update the database and then update the project name field for that task via RJS) :url => { :controller => :tasks, :action => :update, ''task[project_id]''=> project.id.to_s } #TODO there is probably a better way to refer to the task''s project_id so that we can avoid the extra line in the update action of the task controller ); %> <% end %> </ul> <ul>Contexts <% for context in @contexts %> <% context_id = "context_#{context.id}" %> <li id="<%= context_id %>" class="context" style="background-color: #CCC; margin: 0 20px 2px 0;"> <%=h context.name %> </li> <%= drop_receiving_element( context_id, # The id of the receiving element :accept => "task_name", # The CSS class of the dropped elememt #The action to call (update the database and then update the project name field for that task via RJS) :url => { :controller => :tasks, :action => :update, ''task[context_id]''=> context.id.to_s } #TODO there is probably a better way to refer to the task''s context_id so that we can avoid the extra line in the update action of the task controller ); %> <% end %> </ul> </div> What is the best way to do this? Thanks, Bill -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
1. You could create a partial with code between for and end, not including them. Then u can render that partial using render :partial => ''something'', :collection => @projects. 2. dom_id(project) is same as "project_#{project.id}" 3. Try content_tag_for(:li, project, ...) instead of <li id="<%project_id %>"... You can read more about all of these methods in rails documentation page. On Jan 1, 11:33 pm, Bill Devaul <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am new to this and need some help DRYing this view code: > > <div style="float: left;"> > <h3>drop task name</h3> > <ul>Projects > <% for project in @projects %> > <% project_id = "project_#{project.id}" %> > <li id="<%= project_id %>" class="project" style="background-color: > #CCC; margin: 0 20px 2px 0;"> > <%=h project.name %> > </li> > > <% #TODO need to DRY up the drop_receiving_element, perhaps with a > helper%> > > <%= drop_receiving_element( > project_id, # The id of the receiving > element > :accept => "task_name", # The CSS class of the > dropped element > #The action to call (update the database and then update the > project name field for that task via RJS) > :url => { :controller => :tasks, :action => :update, > ''task[project_id]''=> project.id.to_s } > #TODO there is probably a better way to refer to the task''s > project_id so that we can avoid the extra line in the update action of > the task controller > ); %> > <% end %> > </ul> > > <ul>Contexts > <% for context in @contexts %> > <% context_id = "context_#{context.id}" %> > <li id="<%= context_id %>" class="context" style="background-color: > #CCC; margin: 0 20px 2px 0;"> > <%=h context.name %> > </li> > <%= drop_receiving_element( > context_id, # The id of the receiving > element > :accept => "task_name", # The CSS class of the > dropped elememt > #The action to call (update the database and then update the > project name field for that task via RJS) > :url => { :controller => :tasks, :action => :update, > ''task[context_id]''=> context.id.to_s } > #TODO there is probably a better way to refer to the task''s > context_id so that we can avoid the extra line in the update action of > the task controller > ); %> > <% end %> > </ul> > </div> > > What is the best way to do this? > > Thanks, > Bill > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Andrius Chamentauskas wrote:> 1. You could create a partial with code between for and end, not > including them. Then u can render that partial using render :partial > => ''something'', :collection => @projects. > 2. dom_id(project) is same as "project_#{project.id}" > 3. Try content_tag_for(:li, project, ...) instead of <li id="<%> project_id %>"... > > You can read more about all of these methods in rails documentation > page. > > On Jan 1, 11:33�pm, Bill Devaul <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Many thanks! My Rails skills are improving by the day. Here is what I''m using now: <div style="float: left;"> <h3>drop task name</h3> <ul>Projects <% for project in @projects %> <%= render :partial => "drop_belongs_to_list", :locals => { :drop_item => project } %> <% end %> </ul> <ul>Contexts <% for context in @contexts %> <%= render :partial => "drop_belongs_to_list", :locals => { :drop_item => context } %> <% end %> </ul> </div> and the partial is: <%= content_tag :li, (link_to (h drop_item.name), (drop_item)), :class => drop_item.class.to_s.downcase, :id=> dom_id(drop_item) %> <%= drop_receiving_element( dom_id(drop_item), # The id of the receiving element :accept => "task_name", # The CSS class of the dropped element #The action to call (update the database and then update the project name field for that task via RJS) #Not RESTful yet :url => { :controller => :tasks, :action => :update, "task[#{drop_item.class.to_s.downcase}_id]" => drop_item.id.to_s } ); %> Far more readable in the main view. If I could only make the drop_receiving_element RESTful, I''d be all set! Bill -- 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 -~----------~----~----~----~------~----~------~--~---