can display relation between author
This commit is contained in:
parent
f89a6194c4
commit
9759a32394
|
@ -1,6 +1,7 @@
|
||||||
class Desktop::CoAuthorsController < ApplicationController
|
class Desktop::CoAuthorsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@co_authors = CoAuthor.where(name_id: current_user.id)
|
@co_authors = CoAuthor.where(name_id: current_user.id)
|
||||||
|
@co_author_relations = CoAuthorRelation.all
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => false}
|
format.html { render :layout => false}
|
||||||
|
@ -27,6 +28,7 @@ class Desktop::CoAuthorsController < ApplicationController
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@co_author = CoAuthor.find(params[:id])
|
@co_author = CoAuthor.find(params[:id])
|
||||||
|
@co_author_relations = CoAuthorRelation.all
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => false}
|
format.html { render :layout => false}
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,9 +6,8 @@ class CoAuthor
|
||||||
field :name_id, type: BSON::ObjectId
|
field :name_id, type: BSON::ObjectId
|
||||||
field :co_author, localize: true
|
field :co_author, localize: true
|
||||||
field :email
|
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/
|
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/
|
||||||
validates :email, format: { with: VALID_EMAIL_REGEX },
|
validates :email, format: { with: VALID_EMAIL_REGEX },
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
|
|
||||||
<%= f.label :type%><br />
|
<%= 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(
|
<%= options_for_select(
|
||||||
@co_author_relations.map do |relation|
|
@co_author_relations.map do |relation|
|
||||||
[relation.relation, relation.id]
|
[relation.relation, relation.id]
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= co_author.co_author %></td>
|
<td><%= co_author.co_author %></td>
|
||||||
<td><%= co_author.email %></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 '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>
|
<td><%= link_to 'Destroy', desktop_co_author_path(co_author), method: :delete, confirm: 'Are you sure?', :class=>"bt-delete" %></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
19
db/seeds.rb
19
db/seeds.rb
|
@ -2,8 +2,9 @@ require 'factory_girl'
|
||||||
require 'faker'
|
require 'faker'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
WritingJournal.destroy_all
|
|
||||||
CoAuthor.destroy_all
|
CoAuthor.destroy_all
|
||||||
|
CoAuthorRelation.destroy_all
|
||||||
|
WritingJournal.destroy_all
|
||||||
|
|
||||||
data = File.read("db/data")
|
data = File.read("db/data")
|
||||||
data_json = JSON.parse(data)
|
data_json = JSON.parse(data)
|
||||||
|
@ -16,13 +17,21 @@ name_en = name_en.map do |p| Faker::Name::name end
|
||||||
email = Array.new 51,""
|
email = Array.new 51,""
|
||||||
email= email.map do |p| Faker::Internet.email end
|
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
|
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|
|
factory(:co_author_candidate, class: "CoAuthor") do |f|
|
||||||
|
|
||||||
f.sequence(:co_author_translations) do |n|
|
f.sequence(:co_author_translations) do |n|
|
||||||
{ zh_tw: "#{name_tw[n]}",
|
{ zh_tw: "#{name_tw[n]}",
|
||||||
en: "#{name_en[n]}" }
|
en: "#{name_en[n]}" }
|
||||||
end
|
end
|
||||||
f.sequence(:type) do |n| "#{type[n%5]}" end
|
f.sequence(:type) do |n| "#{type[n%5]}" end
|
||||||
f.sequence(:email) do |n| "#{email[n]}" end
|
f.sequence(:email) do |n| "#{email[n]}" end
|
||||||
|
@ -81,6 +90,9 @@ FactoryGirl.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
10.times.each do
|
||||||
|
FactoryGirl.create(:type)
|
||||||
|
end
|
||||||
|
|
||||||
50.times.each do
|
50.times.each do
|
||||||
FactoryGirl.create(:paper_record)
|
FactoryGirl.create(:paper_record)
|
||||||
|
@ -89,3 +101,4 @@ end
|
||||||
50.times.each do
|
50.times.each do
|
||||||
FactoryGirl.create(:co_author_candidate)
|
FactoryGirl.create(:co_author_candidate)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in New Issue