Permalink
Browse files

WE ARE DONE

  • Loading branch information...
1 parent d740383 commit 62b42b9217155311c20b8ae1308fde840e69dc33 @jamierumbelow committed Nov 13, 2011
@@ -129,3 +129,27 @@ h2 {
#notepad-not-logged {color: #fff; font-size: 16px; line-height: 25px; padding: 15px ;}
.underline { text-decoration: underline; }
+
+
+#new-note-wrap {
+ width: 550px;
+ margin: 0 auto;
+ text-align: center;
+ padding: 15px 0;
+}
+
+#new-note-wrap h2 {
+ font-size: 28px;
+ font-weight: bold;
+ color: white;
+}
+
+#new-note-wrap input {
+ margin: 15px;
+ padding: 10px;
+ width: 500px;
+}
+
+#new-note-wrap input[type="submit"] {
+ width: 200px;
+}
@@ -14,6 +14,13 @@ def show
@git.push('origin master').!
end
end
+
+ def new
+ @note = Note.new
+ @courses = Course.find_all_by_university_id(89)
+
+ render :action => 'new'
+ end
def create
@pad = Note.create!(params[:note])
View
@@ -5,4 +5,8 @@ class Course < ActiveRecord::Base
define_index do
indexes :name
end
+
+ def to_s
+ name
+ end
end
View
@@ -3,6 +3,7 @@ class Note < ActiveRecord::Base
has_and_belongs_to_many :tags
after_create :create_git_stuff
+ after_create :reindex
define_index do
indexes :title
@@ -39,9 +40,29 @@ def root_path
protected
def create_git_stuff
+ unless File.exists?(root_path + "/" + course.university.name.parameterize)
+ Dir.mkdir(root_path + "/" + course.university.name.parameterize)
+ end
+
+ unless File.exists?(root_path + "/" + course.university.name.parameterize + '/' + course.name.parameterize)
+ Dir.mkdir(root_path + "/" + course.university.name.parameterize + '/' + course.name.parameterize)
+ end
+
+ File.open git_file_path, 'w+' do |f|
+ f.puts ''
+ end
+
@git = Gittastic.new(root_path)
@git.add(relative_git_file_path).and.commit('-m "Adding lecture note ' + title + ' (' + course.university.name + ' - ' + course.name + ')"').and.push('origin master').!
@git.pull('origin master').!
@git.push('origin master').!
end
+
+ def reindex
+ pid = fork do
+ exec "cd #{Rails.root} && rake thinking_sphinx:reindex"
+ end
+
+ Process.kill "HUP", pid
+ end
end
@@ -0,0 +1,21 @@
+<div id="new-note-wrap">
+ <%= form_for @note do |f| -%>
+ <h2>What course?</h2>
+
+ <br />
+ <br />
+
+ <p><%= f.select :course_id, @courses.collect { |c| [ c.name, c.id ] } %></p>
+
+ <br />
+ <br />
+
+ <h2>What lecture is this?</h2>
+ <br />
+ <%# f.hidden_field :course_id, 6911 %>
+ <p>
+ <%= f.text_field :title %><br />
+ <%= f.submit "Edit!" %>
+ </p>
+ <% end -%>
+</div>
@@ -6,5 +6,5 @@
</div>
<% end %>
<% else %>
- <p>No results found. Try re-wording your search query.</p>
+ <p>No results found. Try re-wording your search query, or you could <%= link_to "create a new lecture note?", new_note_path %></p>
<% end %>
View
@@ -1,5 +1,5 @@
Revisionhub::Application.routes.draw do
- resources :notes, :only => [ :show, :create, :update ]
+ resources :notes, :only => [ :show, :new, :create, :update ]
resources :searches, :only => [ :create ] # POST /searches
devise_for :users
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 62b42b9

Please sign in to comment.