Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testimonials fully RESTful, and loads more refactored as i went.
- Loading branch information
Aimee Daniells
committed
Apr 13, 2009
1 parent
16c73ce
commit d53462a
Showing
24 changed files
with
310 additions
and
226 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,60 @@ | ||
class TestimonialsController < ApplicationController | ||
|
||
before_filter :login_required, :only => [:edit, :update] | ||
before_filter :admin_authorised, :only => [:edit, :update] | ||
|
||
# GET /testimonials | ||
def index | ||
redirect_to :action => 'list' | ||
@testimonials = Testimonial.approved | ||
end | ||
|
||
def list | ||
@testimonials = Testimonial.find(:all, :conditions => "approved = 1", :order => "id desc") | ||
|
||
unless session[:person].nil? | ||
if session[:person].status == "Site Creator" | ||
@editaccess = true | ||
else | ||
@editaccess = false | ||
end | ||
end | ||
|
||
end | ||
|
||
|
||
# GET /testimonials/new | ||
def new | ||
@testimonial = Testimonial.new | ||
|
||
unless session[:person].nil? | ||
if logged_in? | ||
@testimonial.name = session[:person].name | ||
@testimonial.login_id = session[:person].login | ||
end | ||
end | ||
|
||
# POST /testimonials | ||
def create | ||
@testimonial = Testimonial.new(params[:testimonial]) | ||
if validate_recap(params, @testimonial.errors) && @testimonial.save | ||
flash[:notice] = 'Thank you. Your testimonial will appear here once approved.' | ||
|
||
@email = Email.new | ||
@email.subject = "New MyChores testimonial from " + @testimonial.name + " (" + @testimonial.login_id + ")" | ||
@email.message = @testimonial.message | ||
|
||
@email.message += " | ||
Approve it here: " | ||
|
||
@email.message += "http://www.mychores.co.uk/testimonials/edit/" + @testimonial.id.to_s | ||
|
||
@email.to = "contact@mychores.co.uk" | ||
@email.save | ||
|
||
redirect_to :action => 'list' | ||
else | ||
render :action => 'new' | ||
end | ||
if recaptcha_valid?(params, @testimonial) | ||
if @testimonial.save | ||
flash[:notice] = 'Thank you. Your testimonial will appear here once approved.' | ||
@email = Email.new | ||
@email.to = "contact@mychores.co.uk" | ||
@email.subject = "New MyChores testimonial from #{@testimonial.name} (#{@testimonial.login_id})" | ||
@email.message = "#{@testimonial.message}\n\nApprove it here: #{edit_testimonial_url(@testimonial)}" | ||
@email.save | ||
redirect_to(testimonials_path) | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
end | ||
|
||
# GET /testimonials/1/edit | ||
def edit | ||
if session[:person].status == "Site Creator" | ||
@testimonial = Testimonial.find(params[:id]) | ||
end | ||
@testimonial = Testimonial.find(params[:id]) | ||
end | ||
|
||
# PUT /testimonials/1 | ||
def update | ||
@testimonial = Testimonial.find(params[:id]) | ||
if session[:person].status == "Site Creator" | ||
if @testimonial.update_attributes(params[:testimonial]) | ||
flash[:notice] = 'Testimonial was successfully updated.' | ||
redirect_to :action => 'list' | ||
else | ||
render :action => 'edit' | ||
end | ||
if @testimonial.update_attributes(params[:testimonial]) | ||
flash[:notice] = 'Testimonial was successfully updated.' | ||
redirect_to testimonials_path | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
|
||
protected | ||
|
||
def recaptcha_valid?(params, testimonial) | ||
return true if %w(development test).include?(RAILS_ENV) | ||
validate_recap(params, testimonial.errors) | ||
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
= f.error_messages | ||
|
||
%table | ||
%tr | ||
%th= label(:testimonial, :message, 'Testimonial') | ||
%td= text_area(:testimonial, :message, :rows => 12) | ||
|
||
- if controller.admin? | ||
%tr | ||
%th= label(:testimonial, :short_message, 'Short version') | ||
%td= text_area(:testimonial, :short_message, :rows => 6) | ||
|
||
%tr | ||
%th= label(:testimonial, :name, 'Your name') | ||
%td= text_field(:testimonial, :name, :maxlength => 50, :class => 'styled') | ||
%tr | ||
%th= label(:testimonial, :login_id, 'Login ID') | ||
%td= text_field(:testimonial, :login_id, :maxlength => 40, :class => 'styled') | ||
|
||
- if controller.admin? | ||
%tr | ||
%th= label(:testimonial, :approved) | ||
%td= check_box(:testimonial, :approved) | ||
- else | ||
%tr | ||
%th reCAPTCHA | ||
%td= get_captcha() | ||
|
||
%br/ | ||
%br/ |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- @heading = 'Edit testimonial' | ||
|
||
- form_for(@testimonial) do |f| | ||
= render(:partial => 'form', :locals => {:f => f}) | ||
|
||
= f.submit('Save') |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.