-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added inline editing
- Loading branch information
Showing
23 changed files
with
950 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class NoteController < ApplicationController | ||
|
||
before_filter :login_required | ||
before_filter :user_info | ||
before_filter :notebooks_info | ||
|
||
before_filter :notebook_info | ||
before_filter :note_info, :except => [:index, :new, :create] | ||
|
||
def notebook_info | ||
@notebook = Notebook.find(params[:notebook_id]) | ||
end | ||
|
||
def note_info | ||
@note = Note.find(params[:id]) | ||
end | ||
|
||
def show | ||
respond_to do |format| | ||
format.html { render :text => @note.display }# show.html.erb | ||
format.xml { render :xml => @notebook } | ||
end | ||
end | ||
|
||
def new | ||
@note = Note.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @note } | ||
end | ||
end | ||
|
||
def create | ||
@note = Note.new(params[:note]) | ||
@note.notebook = @notebook | ||
|
||
respond_to do |format| | ||
if @note.save | ||
flash[:notice] = 'Note was successfully created.' | ||
format.html { redirect_to :action => "show", :id => @note.id } | ||
format.xml { render :xml => @note, :status => :created, :location => @note } | ||
else | ||
format.html { render :action => "new" } | ||
format.xml { render :xml => @note.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
|
||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @note.update_attributes(params[:note]) | ||
flash[:notice] = 'Panel was successfully updated.' | ||
format.html { redirect_to :action => "show", :id => @note.id} | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @note.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module NoteHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Note < ActiveRecord::Base | ||
|
||
belongs_to :notebook | ||
|
||
validates_presence_of :notebook_id | ||
|
||
def display | ||
"<div class='note' id='note_#{self.id}'><h3>#{self.name}</h3> #{self.content}</div>" | ||
end | ||
|
||
def before_create | ||
if self.notebook.notes.length > 0 | ||
self.rank = self.notebook.notes.maximum(:rank) + 1 | ||
else | ||
self.rank = 0 | ||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-form_for @note, :url => { :action => "update" }, :html => { :id => "note_form" } do |f| | ||
|
||
= f.error_messages | ||
|
||
%p | ||
=f.text_field :name | ||
|
||
%p | ||
=f.text_area :content, :rows => 4 | ||
|
||
%p | ||
= submit_tag 'save' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-form_for @note, :url => { :action => "create" }, :html => { :id => "note_form" } do |f| | ||
|
||
= f.error_messages | ||
|
||
%p | ||
=f.text_field :name | ||
|
||
%p | ||
=f.text_area :content, :rows => 4 | ||
|
||
%p | ||
= submit_tag 'save' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,6 @@ | |
%p | ||
=f.text_field :name | ||
|
||
%p | ||
=f.text_area :content | ||
|
||
%p | ||
= submit_tag 'save' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,6 @@ | |
%p | ||
=f.text_field :name | ||
|
||
%p | ||
=f.text_area :content | ||
|
||
%p | ||
= submit_tag 'save' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
%h2=@notebook.name | ||
#notebook_header | ||
%h2=@notebook.name | ||
|
||
%a{:href => "/notebook/edit/#{@notebook.id}"} edit | ||
%a{:href => "/notebook/edit/#{@notebook.id}"} edit | ||
|
||
#notebook_content | ||
=@notebook.content | ||
|
||
%button#new_note new note | ||
|
||
#messages | ||
|
||
.content | ||
=@notebook.display |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateNotes < ActiveRecord::Migration | ||
def self.up | ||
create_table :notes do |t| | ||
t.integer :notebook_id | ||
t.string :name | ||
t.text :content | ||
t.integer :rank, :default => 0 | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :notes | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.