can display relation between author

This commit is contained in:
Rueshyna 2012-12-03 17:16:28 +08:00 committed by chris
parent f89a6194c4
commit 9759a32394
5 changed files with 22 additions and 7 deletions

View File

@ -1,6 +1,7 @@
class Desktop::CoAuthorsController < ApplicationController
def index
@co_authors = CoAuthor.where(name_id: current_user.id)
@co_author_relations = CoAuthorRelation.all
respond_to do |format|
format.html { render :layout => false}
@ -27,6 +28,7 @@ class Desktop::CoAuthorsController < ApplicationController
def edit
@co_author = CoAuthor.find(params[:id])
@co_author_relations = CoAuthorRelation.all
respond_to do |format|
format.html { render :layout => false}
end

View File

@ -6,9 +6,8 @@ class CoAuthor
field :name_id, type: BSON::ObjectId
field :co_author, localize: true
field :email
field :type
has_and_belongs_to_many :co_author_relations
belongs_to :co_author_relations
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
validates :email, format: { with: VALID_EMAIL_REGEX },

View File

@ -17,7 +17,7 @@
<%= f.label :type%><br />
<select name="co_author[type]" id="" class="s_grid s_grid_4">
<select name="co_author[co_author_relations_id]" id="" class="s_grid s_grid_4">
<%= options_for_select(
@co_author_relations.map do |relation|
[relation.relation, relation.id]

View File

@ -17,7 +17,8 @@
<tr>
<td><%= co_author.co_author %></td>
<td><%= co_author.email %></td>
<td><%= co_author.type%></td>
<td><%= @co_author_relations.find(co_author.co_author_relations_id).relation \
unless co_author.co_author_relations_id.nil?%></td>
<td><%= link_to 'Edit', edit_desktop_co_author_path(co_author), :class => "bt-edit" %></td>
<td><%= link_to 'Destroy', desktop_co_author_path(co_author), method: :delete, confirm: 'Are you sure?', :class=>"bt-delete" %></td>
</tr>

View File

@ -2,8 +2,9 @@ require 'factory_girl'
require 'faker'
require 'json'
WritingJournal.destroy_all
CoAuthor.destroy_all
CoAuthorRelation.destroy_all
WritingJournal.destroy_all
data = File.read("db/data")
data_json = JSON.parse(data)
@ -16,8 +17,16 @@ name_en = name_en.map do |p| Faker::Name::name end
email = Array.new 51,""
email= email.map do |p| Faker::Internet.email end
type = ["friend", "teacher", "student", "mate", "relation"]
type = ["friend0", "teacher0", "student0", "mate0", "relation0", "friend1", "teacher1", "student1", "mate1", "relation1"]
FactoryGirl.define do
factory(:type, class: "CoAuthorRelation") do |f|
f.sequence(:relation_translations) do |n|
{ zh_tw: "#{type[n%type.size]}",
en: "#{type[n%type.size]}" }
end
end
factory(:co_author_candidate, class: "CoAuthor") do |f|
f.sequence(:co_author_translations) do |n|
@ -81,6 +90,9 @@ FactoryGirl.define do
end
end
10.times.each do
FactoryGirl.create(:type)
end
50.times.each do
FactoryGirl.create(:paper_record)
@ -89,3 +101,4 @@ end
50.times.each do
FactoryGirl.create(:co_author_candidate)
end