Created
May 8, 2012 00:47
-
-
Save kibaekr/2631734 to your computer and use it in GitHub Desktop.
This file contains 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
<%= form_for @syllabus, :html => { :class => "form-horizontal" } do |f| %> | |
<% if @syllabus.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@syllabus.errors.count, "error") %> prohibited this syllabus from being saved:</h2> | |
<ul> | |
<% @syllabus.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<fieldset> | |
<div class="row"> | |
<div class="span3"> | |
<div><%= f.label :Title_Image %> | |
<%= f.file_field :image %></div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="span3"> | |
<%= f.label :category %> | |
<%= select(:syllabus, :category, Syllabus::CATEGORIES) %> | |
</div> | |
<div class="span3"> | |
<%= f.label :difficulty %> | |
<%= select(:syllabus, :difficulty, Syllabus::DIFFICULTIES) %> | |
</div><br /> | |
</div> | |
<div class="row"> | |
<div class="span7"> | |
<div class="field"> | |
<%= f.label :title, "Syllabus Title" %> | |
<%= f.text_field :title, :class => 'span7', :placeholder => "What topic does this syllabus cover?" %> | |
</div> | |
<div class="field"> | |
<%= f.label :description, "Syllabus Description" %> | |
<%= f.text_area :description, :class => 'span7', :rows => '5', :placeholder =>"Who is this syllabus for, and what will a user be able to do after completing this syllabus?" %> | |
</div> | |
<br /> | |
<%= f.fields_for :missions do |builder| %> | |
<%= render 'mission_fields', :f => builder %> | |
<% end %> | |
<div class="add-mission-link"> | |
<%= link_to_add_fields "Add Mission", f, :missions %> | |
</div> | |
<div class="actions"> | |
<%= f.submit "Create Syllabus", :class => "btn btn-primary" %> | |
<%= f.submit "Save Draft", :class => "btn btn-danger" %> | |
</div> | |
</div> | |
</div> | |
</div> | |
</fieldset> | |
<% end %> |
This file contains 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 class ="fields"> | |
<div class="well"> | |
<p> | |
<div class="add-mission-link"> | |
<%= link_to_remove_fields "Remove Mission", f %> | |
</div> | |
<%= f.label :title, "Mission Title" %> | |
<%= f.text_field :title, :class => 'row span6' %> | |
<%= f.cktext_area :content, :toolbar => 'MyToolbar', :class => 'row span6', :rows => '5', :placeholder => "What is the first step a learner should do? (e.g. Watch an intro video, read certain article)" %> | |
<%# f.label :content, "Mission Content" %> | |
<%# f.text_area :content, :class => 'row span6', :rows => '5' %> | |
</p> | |
</div> | |
</div> | |
This file contains 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 Mission < ActiveRecord::Base | |
attr_accessible :content, :title | |
acts_as_voteable | |
belongs_to :syllabus | |
belongs_to :author, :class_name => "User", :foreign_key => "author_id" | |
has_many :completed_missions | |
has_many :users, :through => :completed_missions | |
validates :content, :presence => true | |
validates :title, :presence => true | |
end |
This file contains 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
#EXCERPT OF THE MISSIONS CONTROLLER | |
def new | |
@mission = Mission.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @mission } | |
end | |
end | |
# GET /missions/1/edit | |
def edit | |
@mission = Mission.find(params[:id]) | |
end | |
# POST /missions | |
# POST /missions.json | |
def create | |
@mission = Mission.new(params[:mission]) | |
@mission.author_id = current_user.id | |
respond_to do |format| | |
if @mission.save | |
@mission.author.increment!(:userpoints, 10) | |
format.html { redirect_to @mission, notice: "You've earned 10 Street Creds for creating a mission!" } | |
format.json { render json: @mission, status: :created, location: @mission } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @mission.errors, status: :unprocessable_entity } | |
end | |
end | |
end |
This file contains 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 Syllabus < ActiveRecord::Base | |
belongs_to :author, :class_name => "User", :foreign_key => "author_id" | |
has_many :syllabus_users | |
has_many :users, :through => :syllabus_users | |
has_many :missions, :order=> "created_at ASC" | |
accepts_nested_attributes_for :missions | |
has_many :syl_comments, :dependent => :destroy | |
mount_uploader :image, SyllabusImageUploader | |
acts_as_voteable | |
validates :author_id, :presence => true | |
validates :title, :presence => true | |
validates :description, :presence => true | |
validates :difficulty, :presence => true | |
#validates :intendedtime, :presence => true | |
DIFFICULTIES = ['Beginner', 'Medium', 'Advanced'] | |
CATEGORIES = ['Technology and Internet', 'Creative Arts and Music', 'Academics and Test Prep', 'Business and Professional', 'Sports and Health', 'Language', 'Game', 'Lifestyle', 'Other'] | |
SORT = ['Top','Recent'] | |
end |
This file contains 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
def new | |
@syllabus = Syllabus.new | |
missions = @syllabus.missions.build | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @syllabus } | |
end | |
end | |
def create | |
if params[:commit] == "Create Syllabus" | |
sylordraft = "Syllabus" | |
#below is where the problem exists, I think# | |
@syllabus = current_user.creations.build(params[:syllabus]) | |
elsif params[:commit] == "Save Draft" | |
@syllabus = current_user.creations.build(params[:syllabus].merge(:active => false)) | |
sylordraft = "Draft" | |
end | |
respond_to do |format| | |
if @syllabus.save | |
if params[:commit] == "Create Syllabus" | |
@syllabus.author.increment!(:userpoints, 25) | |
format.html { redirect_to @syllabus, notice: "You've earned 25 Street Creds for creating " + sylordraft + "! Go to your profile if you want to update the syllabus." } | |
format.json { render json: @syllabus, status: :created, location: @syllabus } | |
elsif params[:commit] == "Save Draft" | |
format.html { redirect_to edit_syllabus_path(@syllabus), notice: sylordraft + ' was successfully saved. You can keep writing or come back later and continue where you left off in your profile page' } | |
format.json { head :ok } | |
end | |
else | |
format.html { render action: "new" } | |
format.json { render json: @syllabus.errors, status: :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment