Created
December 5, 2012 20:34
-
-
Save chocnut/4219241 to your computer and use it in GitHub Desktop.
references
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="reference-form"> | |
<%= form_for @reference, :remote => true do |f| %> | |
<div> | |
<%= f.text_field :name, :title => "Reference Name", :class => "reference-field" %> | |
<%= f.text_field :phone_number, :title => "Phone Number", :class => "reference-field" %> | |
<%= f.text_field :email, :title => "Email", :class => "reference-field" %> | |
<%= f.select :relationship, | |
"<option value='fr'>Friend</option> | |
<option value='cw'>Co-Worker</option> | |
<option value='fa'>Family</option>".html_safe, | |
:include_blank => true %> | |
</div> | |
<div> | |
Use this reference as: | |
<label for="reference_for_General"> | |
<%= radio_button_tag :reference_for, 'General' %> General References (For all services) | |
</label><br/> | |
<label for="reference_for_Profile"> | |
<%= radio_button_tag :reference_for, 'Profile' %> Specific for | |
</label> | |
<%= f.fields_for :reference_types do |rf| %> | |
<%= rf.select(:name, ReferenceType::PROFILE_TYPES.collect {|x| x }, | |
{ :include_blank => false }, | |
{ :multiple => true, :size => 7 } | |
) %> | |
<% end %> | |
</div> | |
<div> | |
Reference Privacy Level | |
<label for="privacy_Private"><%= f.radio_button :private, '1'%> Publish this reference in my profile</label> | |
<label for="privacy_Request"><%= f.radio_button :private, '0'%> Keep this reference only available upon request</label> | |
</div> | |
<div class="actions"> | |
<%= submit_tag 'Save' %> | |
</div> | |
<% end %> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started POST "/references" for 127.0.0.1 at 2012-12-06 04:38:23 +0800 | |
Processing by ReferencesController#create as JS | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"r4js/4bPNwWKibMIkXpjY8guaB12DDyDfEqI7PRAnmU=", "reference"=>{"name"=>"Test Name", "phone_number"=>"123-123-123", "email"=>"Test", "relationship"=>"fr", "reference_types_attributes"=>{"0"=>{"name"=>["", "bs", "na", "go", "ps"]}}, "private"=>"1"}, "reference_for"=>"Profile", "commit"=>"Save"} | |
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 LIMIT 1 | |
(0.1ms) BEGIN | |
SQL (0.4ms) INSERT INTO `references` (`created_at`, `email`, `name`, `phone_number`, `private`, `relationship`, `updated_at`, `user_id`) VALUES ('2012-12-05 20:38:23', 'Test', 'Test Name', 123, 1, 'fr', '2012-12-05 20:38:23', 9) | |
SQL (0.3ms) INSERT INTO `reference_types` (`created_at`, `name`, `reference_id`, `updated_at`) VALUES ('2012-12-05 20:38:23', '---\n- \'\'\n- bs\n- na\n- go\n- ps\n', 9, '2012-12-05 20:38:23') | |
(38.4ms) COMMIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Reference < ActiveRecord::Base | |
belongs_to :user | |
has_many :reference_types | |
accepts_nested_attributes_for :reference_types | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReferenceType < ActiveRecord::Base | |
belongs_to :reference | |
PROFILE_TYPES = {'Baby Sitter' => 'bs', 'Nanny' => 'na', 'Governess' => 'go', 'Pet Sitter' => 'ps', | |
'HouseKeeper' => 'hk', 'Senior Care' => 'sc', 'Tutor' => 'tu' } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReferencesController < ApplicationController | |
def index | |
end | |
def new | |
@reference = Reference.new | |
@reference.reference_types.build | |
end | |
def create | |
@reference = Reference.new(params[:reference]) | |
@reference.user_id = current_user.id | |
respond_to do |format| | |
if @reference.save | |
format.html { redirect_to(@article, :notice => 'Reference was successfully created.') } | |
format.js | |
else | |
format.html { render :action => "new" } | |
format.js | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment