can display relation between author
This commit is contained in:
parent
6d2fa673c7
commit
5660ff8f03
|
@ -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
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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>
|
||||
|
|
17
db/seeds.rb
17
db/seeds.rb
|
@ -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
|
||||
|
||||
|
|
Reference in New Issue