Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

created assignments views and controllers - crud for assignments and …

…integration with pitches
  • Loading branch information...
commit 0cc0646c58654c2e968da3ea56b632d6d57b132a 1 parent 5f905d5
Dan Newman spherop authored
48 app/controllers/assignments_controller.rb
View
@@ -0,0 +1,48 @@
+class AssignmentsController < ApplicationController
+ resources_controller_for :assignment
+ before_filter :login_required, :except => [:show, :index]
+
+
+ response_for :create do |format|
+ # @assignment.assignment_created_notification
+ format.html do
+ if resource_saved?
+ flash[:success] = 'Successfully created assignment'
+ redirect_to assignment_path(@assignment)
+ else
+ flash[:error] = 'There was an error saving your assignment'
+ render :action => 'new'
+ end
+ end
+ end
+
+ response_for :update do |format|
+ format.html do
+ if resource_saved?
+ flash[:success] = 'Successfully updated assignment'
+ redirect_to assignment_path(@assignment)
+ else
+ flash[:error] = 'There was an error updating your assignment'
+ render :action => 'edit'
+ end
+ end
+ end
+
+ # response_for :destroy do |format|
+ # format.html do
+ # redirect_to myspot_posts_path
+ # end
+ # end
+
+ private
+
+ def new_resource
+ returning resource_service.new(params[resource_name]) do |resource|
+ resource.user = current_user
+ end
+ end
+
+ def authorized?
+ current_user && enclosing_resource.assignable_by?(current_user)
+ end
+end
1  app/controllers/posts_controller.rb
View
@@ -4,7 +4,6 @@ class PostsController < ApplicationController
response_for :create do |format|
- #new_post = Post.find(params[:id])
@post.blog_posted_notification
format.html do
if resource_saved?
2  app/helpers/assignments_helper.rb
View
@@ -0,0 +1,2 @@
+module AssignmentsHelper
+end
2  app/models/assignment.rb
View
@@ -3,7 +3,7 @@ class Assignment < ActiveRecord::Base
belongs_to :user
validates_presence_of :title, :body, :user, :pitch
- has_many :assignment_contributors
+ has_many :assignment_contributors, :dependent => :destroy
has_many :contributors, :through => :assignment_contributors, :source => :contributor, :foreign_key => :user_id
# def blog_posted_notification
11 app/models/pitch.rb
View
@@ -116,6 +116,8 @@ def first(number)
find(:all, :limit => number, :order => 'created_at DESC')
end
end
+ has_many :assignments, :order => "created_at desc", :dependent => :delete_all\
+
has_many :contributor_applications do
def unapproved
find_all_by_approved(false)
@@ -163,6 +165,11 @@ def postable_by?(other_user)
return false if other_user.nil?
user == other_user || other_user.admin? || other_user == fact_checker || contributors.include?(other_user)
end
+
+ def assignable_by?(other_user)
+ return false if other_user.nil?
+ user == other_user || other_user.admin?
+ end
def approvable_by?(current_user)
return false if current_user.nil?
@@ -313,6 +320,10 @@ def dispatch_fact_checker
def has_more_posts_than(number)
posts.size > number
end
+
+ def has_more_assignments_than(number)
+ assignments.size > number
+ end
def donating_groups
Donation.paid.for_pitch(self).map(&:group).uniq.compact
9 app/views/assignments/_assignment.html.haml
View
@@ -0,0 +1,9 @@
+%h3
+ = assignment.title
+.reg-line-height.date.quiet= assignment.created_at
+.double_content_border
+.post_body
+ = truncate_words(assignment.body, 50)
+.read_more
+ = link_to "Read More", pitch_assignment_path(assignment.pitch, assignment)
+.block-spacer-negative
13 app/views/assignments/_form.html.haml
View
@@ -0,0 +1,13 @@
+.box_yellow.create_a_pitch_form
+ .row
+ = f.label :title
+ = f.text_field :title
+ .row
+ = f.label :body
+ = fckeditor_textarea("assignment", "body", :toolbarSet => 'Spotus', :width => '450px', :height => '200px')
+ .row
+ = f.label :media_embed
+ = f.text_area :media_embed, :rows => 4
+ .row
+ = f.submit
+ = link_to 'Back to my pitches', myspot_pitches_path
5 app/views/assignments/edit.html.haml
View
@@ -0,0 +1,5 @@
+.block-spacer
+%h3== Edit this assignment for #{@pitch.headline}
+.span-715.box_white
+ - form_for([@pitch, @assignment]) do |f|
+ = render :partial => 'form', :locals => {:f => f}
23 app/views/assignments/index.html.haml
View
@@ -0,0 +1,23 @@
+- @title = "Spot.us - Assignments for Pitch: #{h @pitch.headline}"
+.block-spacer
+#equalize
+ .span-455.box_white
+ %h2.headline
+ %strong= h @pitch.headline
+ .double_content_border
+ = render :partial => 'news_items/user', :locals => { :news_item => @pitch }
+ %h2.headline
+ Related pitch
+ .pitch_summary
+ .float-left
+ = link_to image_tag(@pitch.featured_image.url(:thumb)), pitch_url(@pitch)
+ %h2
+ = link_to @pitch.headline, pitch_url(@pitch)
+ .block-spacer-negative
+ = render :partial => @pitch.assignments
+ .span-220.column_v.box_white
+ = render :partial => "donations/button", :locals => { :news_item => @pitch }
+ .block-spacer-negative
+ = render :partial => 'pitches/keywords', :locals => {:pitch => @pitch}
+ .span-160.box_white
+ = render :partial => "pitches/supporters", :locals => {:news_item => @pitch}
6 app/views/assignments/new.html.haml
View
@@ -0,0 +1,6 @@
+.block-spacer
+%h3== Make an assignment for #{@pitch.headline}
+.span-715.box_white
+ = render :partial => 'news_items/user', :locals => { :news_item => @pitch }
+ - form_for([@pitch, @assignment]) do |f|
+ = render :partial => 'form', :locals => {:f => f}
34 app/views/assignments/show.html.haml
View
@@ -0,0 +1,34 @@
+- @title = "Spot.us - #{h @assignment.title} - Pitch: #{h @assignment.pitch.headline}"
+
+.block-spacer
+#equalize
+ .span-455.box_white
+ %h2.headline
+ %strong= h @assignment.title
+ .double_content_border
+ = render :partial => 'shared/user', :locals => { :user => @assignment.user }
+ .double_content_border.clear
+ %h2.headline
+ Related pitch
+ .pitch_summary
+ .float-left
+ = link_to image_tag(@assignment.pitch.featured_image.url(:thumb)), pitch_url(@assignment.pitch)
+ %h2
+ = link_to @assignment.pitch.headline, pitch_url(@assignment.pitch)
+ .block-spacer-negative
+ .double_content_border
+ = @assignment.body
+ .double_content_border
+ = @assignment.media_embed
+ .span-220.column_v.box_white
+ = render :partial => "donations/button", :locals => { :news_item => @assignment.pitch }
+ .block-spacer-negative
+ - if @assignment.pitch.assignable_by?(current_user)
+ = link_to image_tag('edit_in_red.png'), edit_pitch_assignment_path(@assignment.pitch, @assignment)
+ = render :partial => 'pitches/assignments', :locals => {:pitch => @assignment.pitch}
+ .block-spacer-negative
+ = render :partial => 'pitches/keywords', :locals => {:pitch => @assignment.pitch}
+ .span-160.box_white
+ = render :partial => "news_items/organizational_supporters", :locals => {:news_item => @assignment.pitch}
+ = render :partial => "pitches/group_supporters", :locals => {:news_item => @assignment.pitch}
+ = render :partial => "pitches/supporters", :locals => {:news_item => @assignment.pitch}
2  app/views/pitches/_action_buttons.html.haml
View
@@ -18,6 +18,8 @@
.centered= link_to image_tag('feature_this_pitch.png'), feature_pitch_path(pitch), :method => :put, :title => "Feature This Pitch"
- if pitch.postable_by?(current_user)
= link_to image_tag('make_blog_post.gif'), new_pitch_post_path(pitch), :title => "Make Blog Post"
+ - if pitch.assignable_by?(current_user)
+ = link_to image_tag('make_assignment.gif'), new_pitch_assignment_path(pitch), :title => "Make Assignment"
- if pitch.story && pitch.fact_checker == current_user
= link_to image_tag('go_to_story.gif'), story_path(pitch.story), :title => "Go To Story"
- if pitch.fully_funded? && current_user == pitch.user
11 app/views/pitches/_assignments.html.haml
View
@@ -0,0 +1,11 @@
+- if pitch.assignments.any?
+ .block-spacer-negative
+ %h3 Assignments
+ .double_content_border
+ - pitch.assignments.first(5).each do |assignment|
+ %h4.reg-line-height
+ = link_to h(assignment.title), pitch_assignment_path(pitch, assignment)
+ .reg-line-height.small.quiet= assignment.created_at.to_s(:date)
+ .body= truncate_words(strip_tags(assignment.body), 20)
+ - if pitch.has_more_assignments_than(5)
+ = link_to "View all", pitch_assignments_path(pitch)
2  app/views/pitches/show.html.haml
View
@@ -129,6 +129,8 @@
= @pitch.license
= render :partial => 'posts', :locals => {:pitch => @pitch}
.block-spacer-negative
+ = render :partial => 'assignments', :locals => {:pitch => @pitch}
+ .block-spacer-negative
= render :partial => 'keywords', :locals => {:pitch => @pitch}
.span-160.box_white
1  config/routes.rb
View
@@ -11,6 +11,7 @@
map.resources :pitches, :member => {:feature => :put, :unfeature => :put, :half_fund => :put, :fully_fund => :put, :show_support => :put, :apply_to_contribute => :get, :assign_fact_checker => :put, :blog_posts => :get}, :has_many => :comments do |pitch|
pitch.resources :posts
+ pitch.resources :assignments
end
# facebook acct link
BIN  public/images/make_assignment.gif
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 spec/controllers/assignments_controller_spec.rb
View
@@ -0,0 +1,10 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AssignmentsController do
+
+ #Delete this example and add some real ones
+ it "should use AssignmentsController" do
+ controller.should be_an_instance_of(AssignmentsController)
+ end
+
+end
11 spec/helpers/assignments_helper_spec.rb
View
@@ -0,0 +1,11 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AssignmentsHelper do
+
+ #Delete this example and add some real ones or delete this file
+ it "should be included in the object returned by #helper" do
+ included_modules = (class << helper; self; end).send :included_modules
+ included_modules.should include(AssignmentsHelper)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.