can select relection from relation db
This commit is contained in:
parent
3e1e2c47ec
commit
7ba65caa70
|
@ -18,6 +18,7 @@ class Desktop::CoAuthorsController < ApplicationController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@co_author = CoAuthor.new
|
@co_author = CoAuthor.new
|
||||||
|
@co_author_relations = CoAuthorRelation.all
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => false}
|
format.html { render :layout => false}
|
||||||
|
|
|
@ -13,7 +13,7 @@ class CoAuthor
|
||||||
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 },
|
||||||
allow_blank: true,
|
allow_blank: true,
|
||||||
uniqueness: { case_sensitive: false }
|
uniqueness: { case_sensitive: false }
|
||||||
|
|
||||||
validates :co_author, presence: true
|
validates :co_author, presence: true
|
||||||
before_save { |coauthor| coauthor.email = email.downcase if not coauthor.email.nil?}
|
before_save { |coauthor| coauthor.email = email.downcase if not coauthor.email.nil?}
|
||||||
|
|
|
@ -5,4 +5,6 @@ class CoAuthorRelation
|
||||||
field :relation, localize: true
|
field :relation, localize: true
|
||||||
|
|
||||||
has_and_belongs_to_many :co_authors
|
has_and_belongs_to_many :co_authors
|
||||||
|
|
||||||
|
validates :relation, presence: true
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ class User
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
|
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :validatable
|
||||||
|
|
||||||
mount_uploader :avatar, AvatarUploader
|
mount_uploader :avatar, AvatarUploader
|
||||||
|
|
||||||
|
@ -194,4 +194,4 @@ class User
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,19 +15,14 @@
|
||||||
<%= f.text_field :email %>
|
<%= f.text_field :email %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="s_grid_row">
|
|
||||||
<%= f.label :type%><br />
|
<%= f.label :type%><br />
|
||||||
<select name="co_author[type]" id="" class="s_grid s_grid_4">
|
<select name="co_author[type]" id="" class="s_grid s_grid_4">
|
||||||
<%= options_for_select(
|
<%= options_for_select(
|
||||||
[["朋友","朋友"],
|
@co_author_relations.map do |relation|
|
||||||
["學生","摯友"],
|
[relation.relation, relation.id]
|
||||||
["老師","老師"],
|
end
|
||||||
["摯友","摯友"],
|
)%>
|
||||||
["親戚","親戚"],
|
|
||||||
["同事","同事"],
|
|
||||||
["共同作者","共同作者"]
|
|
||||||
])
|
|
||||||
%>
|
|
||||||
</select>
|
</select>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -120,13 +120,13 @@
|
||||||
</li>
|
</li>
|
||||||
<li class="s_grid_row">
|
<li class="s_grid_row">
|
||||||
|
|
||||||
<select name="writing_journal[journal_author_type_ids][]" id="" class="s_grid s_grid_4">
|
<select name="writing_journal[journal_author_type_ids][]" id="" class="s_grid s_grid_4">
|
||||||
<%= options_for_select(
|
<%= options_for_select(
|
||||||
@author_types.map do |author_type|
|
@author_types.map do |author_type|
|
||||||
[author_type.title, author_type.id]
|
[author_type.title, author_type.id]
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
%>
|
%>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select name="writing_journal[journal_paper_type_ids][]" id="" class="s_grid s_grid_2">
|
<select name="writing_journal[journal_paper_type_ids][]" id="" class="s_grid s_grid_2">
|
||||||
|
|
Loading…
Reference in New Issue