Permalink
Browse files

added seed logic, pulled categorizations out of categories

  • Loading branch information...
1 parent 05fd6ad commit 5ece8da3aed686dcc719a129e33bd62cd601ad70 @jonkarna committed Aug 31, 2010
@@ -1,6 +1,6 @@
class CategorizationsController < ApplicationController
before_filter :authenticate, :except => [:show]
- before_filter :define_back_link
+ before_filter :define_back_link, :except => [:create, :destroy]
%w{move_higher move_lower move_to_top move_to_bottom}.each do |action|
define_method action do
@@ -16,13 +16,11 @@ class CategorizationsController < ApplicationController
end
def show
- @category = Category.find(params[:category_id])
@categorization = Categorization.find(params[:id])
@website = @categorization.website
end
def edit
- @category = Category.find(params[:category_id])
@categorization = Categorization.find(params[:id])
@website = @categorization.website
end
@@ -43,15 +41,14 @@ def create
end
def destroy
- @category = Category.find(params[:category_id])
@categorization = Categorization.find(params[:id])
@categorization.destroy
- redirect_to(edit_category_path(@category))
+ redirect_to(edit_category_path(@categorization.category))
end
private
def define_back_link
- @category = Category.find(params[:category_id])
- @back_link = category_path(@category)
+ @categorization = Categorization.find(params[:id])
+ @back_link = category_path(@categorization.category)
end
end
@@ -6,11 +6,11 @@ def reorder_buttons(categorization)
{:action => "move_lower", :label => "Down"},
{:action => "move_to_top", :label => "Top"},
{:action => "move_to_bottom", :label => "Bottom"}
- ].each do |item|
- result << link_to("#{item[:label]}", send("#{item[:action]}_category_categorization_path", categorization.category, categorization) )
+ ].each do |item|
+ result << link_to("#{item[:label]}", send("#{item[:action]}_categorization_path", categorization) )
result << ' | '
end
- result << link_to('X', category_categorization_path(categorization.category, categorization), :confirm => 'Are you sure?', :method => :delete) + ' ]'
+ result << link_to('X', categorization, :confirm => 'Are you sure?', :method => :delete) + ' ]'
result
end
end
@@ -16,7 +16,7 @@
<div class="box">
<% for website in Website.find(:all) %>
<% unless @category.websites.include?(website) %>
- <%= website.title %> [ <%= link_to 'Add', category_categorizations_path(@category, :website_id => website.id), :method => :post %> ]<br />
+ <%= website.title %> [ <%= link_to 'Add', categorizations_path({:category_id => @category.id, :website_id => website.id}), :method => :post %> ]<br />
<% end %>
<% end %>
</div>
@@ -1,7 +1,7 @@
<h1><%=h @category.name %></h1>
<ul>
<% for categorization in @category.categorizations %>
- <li><%= link_to categorization.website.title, category_categorization_path(@category, categorization) %></li>
+ <li><%= link_to categorization.website.title, categorization %></li>
<% end %>
</ul>
<% if logged_in? %>
@@ -1,6 +1,6 @@
<h1>Editing website</h1>
<%= render :partial => "websites/form" %>
<ul class="individual">
- <li><%= link_to 'Show', category_categorization_path(@category, @categorization) %></li>
+ <li><%= link_to 'Show', @categorization %></li>
<li><%= link_to 'Delete', @website, :confirm => 'Are you sure?', :method => :delete %></li>
</ul>
@@ -1,7 +1,7 @@
<%= render :partial => "websites/website" %>
<% if logged_in? %>
<ul class="individual">
- <li><%= link_to 'Edit', edit_category_categorization_path(@category, @categorization) %></li>
+ <li><%= link_to 'Edit', edit_categorization_path(@categorization) %></li>
<li><%= link_to 'Delete', @website, :confirm => 'Are you sure?', :method => :delete %></li>
</ul>
<% end %>
@@ -1,2 +1,5 @@
<h1>Editing website</h1>
-<%= render :partial => "websites/form" %>
+<%= render :partial => "websites/form" %>
+<ul class="individual">
+ <li><%= link_to 'Delete', @website, :confirm => 'Are you sure?', :method => :delete %></li>
+</ul>
View
@@ -1,14 +1,15 @@
ActionController::Routing::Routes.draw do |map|
map.resources :websites, :except => [:show]
- map.resources :categories, :has_many => :categorizations, :collection => { :move_higher => :post }
+ map.resources :categories
+ map.resources :categorizations
map.resources :sessions, :only => [:new, :create, :destroy]
map.login "/login", :controller => :sessions, :action => :new
map.logout "/logout", :controller => :sessions, :action => :destroy
%w{move_higher move_lower move_to_top move_to_bottom}.each do |action|
instance_eval <<-EOF
- map.#{action}_category_categorization "categories/:category_id/categorizations/:id/#{action}", {:controller => "categorizations", :action => "#{action}"}
+ map.#{action}_categorization "categorizations/:id/#{action}", {:controller => "categorizations", :action => "#{action}"}
EOF
end
View
Binary file not shown.
View
@@ -1,7 +1,36 @@
-# This file should contain all the record creation needed to seed the database with its default values.
-# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
-#
-# Examples:
-#
-# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
-# Major.create(:name => 'Daley', :city => cities.first)
+require 'net/http'
+require 'rexml/document'
+
+Categorization.delete_all
+Website.delete_all
+Category.delete_all
+
+menu = ['Agriculture', 'Transportation', 'Service', 'Construction', 'Manufacturing', 'Retail', 'Community & Tourism', 'Health & Wellness', 'Ecommerce', 'Other']
+url_suffix = ['agriculture', 'transportation', 'service', 'construction', 'manufacturing', 'retail', 'travel', 'health', 'ecommerce', 'other']
+
+url_suffix.each_with_index do |suffix, index|
+ @category = Category.new
+ @category.name = menu[index]
+ @category.save!
+ xml_doc = REXML::Document.new(Net::HTTP.get_response(URI.parse("http://www.sitepro.com/index.cfm?event=flashrotation&flashpiecename=portfolio.websites.#{suffix}")).body)
+ xml_doc.elements.each('flashpiece/flashrecord') do |flashrecord|
+ @website = Website.find_by_title(flashrecord.attributes["title"])
+ if @website.nil?
+ @website = Website.new
+ @website.title = flashrecord.attributes["title"]
+ @website.image = flashrecord.attributes["image"]
+ @website.website = flashrecord.attributes["website"]
+ @website.industry = flashrecord.attributes["industry"]
+ @website.launched = flashrecord.attributes["launched"]
+ @website.features = flashrecord.attributes["features"]
+ @website.challenge = flashrecord.attributes["challenge"]
+ @website.solution = flashrecord.attributes["solution"]
+ @website.save!
+ end
+ @categorization = Categorization.new
+ @categorization.category = @category
+ @categorization.website = @website
+ @categorization.move_to_bottom
+ @categorization.save!
+ end
+end
Oops, something went wrong.

0 comments on commit 5ece8da

Please sign in to comment.