sort+1 unless @layout.stylings.empty?
@layout.stylings.create :layout => @layout,
:style => @style,
:sort => newSort
render :partial => 'style_list'
end
As you can see, you add the new style to the layout in question, and then you find a new
sort value that places the new style at the last point in the list. After that, you render the
partial style_list and return it.
The style_list partial should look like this:
<% for styling in @layout.stylings %>
<%=styling.style.name%> (
<%=styling.style.style_type.name%>)
<%= link_to_remote 'Remove', :update => 'styles',
:url=>{:action => 'remove_style', :id => @layout,
:styling => styling} %>
<% end %>
CHAPTER 7 ?– A RAILS CMS 134
<%= sortable_element 'styles-list',
:url => {:action => 'sort', :id => @layout},
:complete => visual_effect(:highlight, 'styles-list') %>
This is also a bit complicated. First of all, this style list is an ordered list. You need to provide
an id to the ol element, so the sorting can happen later. Walk through each styling and
create an li tag for it, with ids that begin with item_ and the ID of the styling. There??™s also a
link to remove_style for each entry. That is a link_to_remote element too, and it updates the
styles element in the same way as add_style. We??™ll look at remove_style soon. First though,
look at the sortable_element part in the preceding code. That helper makes the magic Ajax
tricks available so your list can be sorted by drag and drop.
Pages:
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226