Created
January 20, 2014 15:41
-
-
Save shosanna/8522255 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
class SolutionsController < AuthenticatedController | |
before_filter :require_admin, only: :index | |
def index | |
@solutions = Solution.scoped | |
end | |
def create | |
solution = Solution.new(params[:solution]) | |
solution.user = current_user | |
solution.save! | |
flash[:notice] = "Good job with this task!" | |
redirect_to dashboard_path | |
end | |
def edit | |
@solution = Solution.find(params[:id]) | |
@task = @solution.task | |
end | |
def update | |
@solution = Solution.find(params[:id]) | |
@task = @solution.task | |
if @solution.update_attributes(params[:solution]) | |
redirect_to dashboard_path, notice: "Solution was updated." | |
else | |
render :edit | |
end | |
end | |
def destroy | |
Solution.find(params[:id]).destroy | |
redirect_to dashboard_path, notice: "Solution was removed" | |
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 Task < ActiveRecord::Base | |
attr_accessible :title, :description, :tag_ids | |
validates_presence_of :title, :description | |
has_many :solutions, dependent: :destroy | |
has_many :users, through: :solutions | |
has_many :taggings | |
has_many :tags, through: :taggings | |
belongs_to :next_step, class_name: "Task" | |
has_one :previous_step, class_name: "Task", foreign_key: "next_step_id" | |
# nasledujici dve metody se pouzivaji pouze pro zjisteni, zda u instance ukolu na kteoru je metoda solved_by volana | |
# ma uzivatel splnene solution - jinymi slovy, jestli ukol uz vyresil. | |
def solution_for(user) | |
solutions.where(user_id: user.id).first | |
end | |
def solved_by?(user) | |
!!solution_for(user) | |
end | |
# vraci pouze mozne ukoly pro uzivatele (ne ty, ktere jiz ma vyresene) | |
# nebo ty u kterych jeste nema vyreseny predchazejici krok - task.previous_step | |
def self.available_for(user) | |
Task.all.reject do |task| | |
task.solved_by?(user) || (task.previous_step && !task.previous_step.solved_by?(user)) | |
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
window.util = { | |
// Function which return number of words. | |
// I need to give it text where I need to know number of words in it. | |
countWords: function(text) { | |
var words = text.split(" "); | |
var count; | |
if (words[words.length - 1] === "") { | |
count = words.length - 1; | |
} else { | |
count = words.length; | |
} | |
return count; | |
}, | |
// Function which returns number of stars according to number of words | |
// I need to give it number of words. | |
starCount: function(count) { | |
if (count > 10 && count < 70) { | |
return 1; | |
} else if (count >= 70 && count < 200) { | |
return 2; | |
} else if (count >= 200) { | |
return 3; | |
} else { | |
return 0; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment