can add relation between co-author

This commit is contained in:
Rueshyna authored and chris committed 2012-12-04 00:31:06 +08:00
1 parent 5dabfe9319
commit 7822ffc33d
18 files changed
+350 -77

No files matched your search

@@ -0,0 +1,32 @@
class Desktop::CoAuthorRelationsController < ApplicationController
def index
@co_author_relations = CoAuthorRelation.all
new
respond_to do |format|
format.html {render layout: false }
end
end
def new
@new_relation = CoAuthorRelation.new
end
def create
@new_relation = CoAuthorRelation.new(params[:co_author_relation])
if @new_relation.save
render json: {success:true, msg: "New Relation successfully saved!"}.to_json
else
error_msg = @new_relation.errors.full_messages.join("<br />")
render json: {success: false, msg: error_msg}.to_json
end
end
def destroy
@co_author_relation = CoAuthorRelation.find(params[:id])
@co_author_relation.destroy
render :json => {success: true, msg: "deleted successfully!"}
end
end
@@ -4,7 +4,6 @@ class Desktop::CoAuthorsController < ApplicationController
respond_to do |format|
format.html { render :layout => false}
format.json { render json: @co_authors }
end
end
@@ -1,6 +1,5 @@
class Desktop::JournalListsController < ApplicationController
# GET /desktop/journal_lists
# GET /desktop/journal_lists.json
def index
level_types = JournalLevelType.all
all_journal_lists = WritingJournal.where(create_user_id: current_user.id)
@@ -18,76 +17,4 @@ class Desktop::JournalListsController < ApplicationController
format.html { render :layout => false}
end
end
=begin
# GET /desktop/journal_lists/1
# GET /desktop/journal_lists/1.json
def show
@desktop_journal_list = Desktop::JournalList.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @desktop_journal_list }
end
end
# GET /desktop/journal_lists/new
# GET /desktop/journal_lists/new.json
def new
@desktop_journal_list = Desktop::JournalList.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @desktop_journal_list }
end
end
# GET /desktop/journal_lists/1/edit
def edit
@desktop_journal_list = Desktop::JournalList.find(params[:id])
end
# POST /desktop/journal_lists
# POST /desktop/journal_lists.json
def create
@desktop_journal_list = Desktop::JournalList.new(params[:desktop_journal_list])
respond_to do |format|
if @desktop_journal_list.save
format.html { redirect_to @desktop_journal_list, notice: 'Journal list was successfully created.' }
format.json { render json: @desktop_journal_list, status: :created, location: @desktop_journal_list }
else
format.html { render action: "new" }
format.json { render json: @desktop_journal_list.errors, status: :unprocessable_entity }
end
end
end
# PUT /desktop/journal_lists/1
# PUT /desktop/journal_lists/1.json
def update
@desktop_journal_list = Desktop::JournalList.find(params[:id])
respond_to do |format|
if @desktop_journal_list.update_attributes(params[:desktop_journal_list])
format.html { redirect_to @desktop_journal_list, notice: 'Journal list was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @desktop_journal_list.errors, status: :unprocessable_entity }
end
end
end
# DELETE /desktop/journal_lists/1
# DELETE /desktop/journal_lists/1.json
def destroy
@desktop_journal_list = Desktop::JournalList.find(params[:id])
@desktop_journal_list.destroy
respond_to do |format|
format.html { redirect_to desktop_journal_lists_url }
format.json { head :ok }
end
end
=end
end
@@ -0,0 +1,2 @@
module Desktop::CoAuthorRelationsHelper
end
+1
View File
@@ -8,6 +8,7 @@ class CoAuthor
field :email
field :type
has_and_belongs_to_many :co_author_relations
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
validates :email, format: { with: VALID_EMAIL_REGEX },
+8
View File
@@ -0,0 +1,8 @@
class CoAuthorRelation
include Mongoid::Document
include Mongoid::Timestamps
field :relation, localize: true
has_and_belongs_to_many :co_authors
end
@@ -0,0 +1,4 @@
<%= form_for(@new_relation , url: desktop_co_author_relations_path ) do |f| %>
<%= f.text_field :relation %>
<%= f.submit "Save" %>
<% end %>
@@ -0,0 +1,18 @@
<h1>Listing co_author_relations</h1>
<%= render 'form' %>
<table>
<tr>
<th>Relation</th>
<th></th>
<th></th>
</tr>
<% @co_author_relations.each do |co_author_relation| %>
<tr>
<td><%= co_author_relation.relation %></td>
<td><%= link_to 'Destroy', desktop_co_author_relation_path(co_author_relation), confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
+1 -1
View File
@@ -1,6 +1,6 @@
<h1>list all coauthor</h1>
<%= link_to "New Co-Author", new_desktop_co_author_path %>
<%= link_to "New Type", "#" %>
<%= link_to "New Type", desktop_co_author_relations_path %>
<table>
<tr>
<th>Name</th>