Permalink
Browse files

fixed rails 2 app

  • Loading branch information...
1 parent 2c2e3f9 commit 98885b7f1b3164a67ddcecdd5cd9cba242e6707d @matenia committed Apr 27, 2011
View
@@ -3,7 +3,12 @@
I have been searching high and low for a plugin that will allow this, and decided to combine a few tools, write a few helper methods and controller actions and roll my own.
-You can find awesome_nested_set at: http://github.com/collectiveidea/awesome_nested_set with setup instructions. (Thank's guys, it really lives up to it's name) - check their wiki for gotchas and cheat sheets
+You can find awesome_nested_set at:
+
+http://github.com/collectiveidea/awesome_nested_set with setup instructions (RAILS 2)
+https://github.com/galetahub/awesome_nested_set (RAILS 3)
+
+(Thank's guys, it really lives up to it's name) - check their wiki for gotchas and cheat sheets
I hope this will help someone else out there having the same problem as I did.
@@ -20,9 +25,17 @@ This works best with a new set, as I have implemented this in a few existing set
Please see the example_app directory for a simple working demo.
NOTE: The demo uses rails 2.3.8
+=== UPDATE (28th April 2011)
+
+see rails3 example (rails 3.0.3 ruby 1.8.7) using https://github.com/galetahub/awesome_nested_set (rails 3 version)
+
== FINAL NOTES
-I will admit that this is not the most efficient way of handling this action, but it does work. I welcome any refactoring suggestions. Feel free to email me at matenia@gmail.com
+I will admit that this is not the most efficient way of handling this action, but it does work well, especially if you're not sorting a nested set frequently. I welcome any refactoring suggestions. Feel free to email me at matenia@gmail.com
+
+== MENTIONS AND CREDITS
+
+Thank you to {Chelsea}[http://twitter.com/chelsearobb] for helping me iron out some stubborn code during a hack-meetup.
== COPYRIGHT
@@ -51,7 +51,7 @@ def array
#loop through each item in the new list (passed via ajax)
newlist.each_with_index do |array, index|
# get the category id of the item being moved
- moved_item_id = array[1][:id].split(/category_/)
+ moved_item_id = array[1][:id].gsub(/category_/,'')
# find the object that is being moved (in database)
@current_category = Category.find_by_id(moved_item_id)
# if this is the first item being moved, move it to the root.
@@ -73,10 +73,10 @@ def array
render :nothing => true
end
def childstuff(mynode, category)
- #loop through it's children
- for child in mynode[:children]
+ #loop through it's children - this is a hash that needs to be sorted
+ for child in mynode[:children].sort
# get the child id from each child passed into the node (the array)
- child_id = child[1][:id].split(/category_/)
+ child_id = child[1][:id].gsub(/category_/,'')
#find the matching category in the database
child_category = Category.find_by_id(child_id)
#move the child to the selected category
@@ -14,8 +14,7 @@
placeholder: 'placeholder',
tabSize: 25,
tolerance: 'pointer',
- toleranceElement: '> div',
-
+ toleranceElement: '> div'
});
$('#status').hide();
$('.save').click(function(){
View
@@ -6,7 +6,8 @@ gem 'rails', '3.0.3'
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
-
+gem 'nifty-generators'
+gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
@@ -0,0 +1,79 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ arel (2.0.6)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ jquery-rails (0.2.6)
+ rails (~> 3.0)
+ thor (~> 0.14.4)
+ mail (2.2.12)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ nifty-generators (0.4.2)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.6)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ sqlite3-ruby (1.3.2)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jquery-rails
+ nifty-generators
+ rails (= 3.0.3)
+ sqlite3-ruby
@@ -0,0 +1,5 @@
+class HomeController < ApplicationController
+ def index
+ end
+
+end
@@ -0,0 +1,23 @@
+module ErrorMessagesHelper
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
+ def error_messages_for(*objects)
+ options = objects.extract_options!
+ options[:header_message] ||= "Invalid Fields"
+ options[:message] ||= "Correct the following errors and try again."
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
+ unless messages.empty?
+ content_tag(:div, :class => "error_messages") do
+ list_items = messages.map { |msg| content_tag(:li, msg) }
+ content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
+ end
+ end
+ end
+
+ module FormBuilderAdditions
+ def error_messages(options = {})
+ @template.error_messages_for(@object, options)
+ end
+ end
+end
+
+ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,2 @@
+module HomeHelper
+end
@@ -0,0 +1,22 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+ def title(page_title, show_title = true)
+ content_for(:title) { h(page_title.to_s) }
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args) }
+ end
+
+ def javascript(*args)
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,2 @@
+<h1>Home#index</h1>
+<p>Find me in app/views/home/index.html.erb</p>
@@ -1,14 +1,19 @@
<!DOCTYPE html>
<html>
-<head>
- <title>Rails3Example</title>
- <%= stylesheet_link_tag :all %>
- <%= javascript_include_tag :defaults %>
- <%= csrf_meta_tag %>
-</head>
-<body>
-
-<%= yield %>
-
-</body>
+ <head>
+ <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
+ <%= stylesheet_link_tag 'reset', '960', 'text', 'application' %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= content_tag :h1, yield(:title) if show_title? %>
+ <%= yield %>
+ </div>
+ </body>
</html>
@@ -1,4 +1,6 @@
Rails3Example::Application.routes.draw do
+ get "home/index"
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -54,5 +56,5 @@
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+ match ':controller(/:action(/:id(.:format)))'
end
Oops, something went wrong.

0 comments on commit 98885b7

Please sign in to comment.