Mercurial > hg > soundsoftware-site
comparison app/controllers/.svn/text-base/news_controller.rb.svn-base @ 22:40f7cfd4df19
* Update to SVN trunk rev 4173
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 24 Sep 2010 14:06:04 +0100 |
parents | 513646585e45 |
children | 94944d00e43c |
comparison
equal
deleted
inserted
replaced
14:1d32c0a0efbf | 22:40f7cfd4df19 |
---|---|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 class NewsController < ApplicationController | 18 class NewsController < ApplicationController |
19 default_search_scope :news | 19 default_search_scope :news |
20 model_object News | 20 model_object News |
21 before_filter :find_model_object, :except => [:new, :index, :preview] | 21 before_filter :find_model_object, :except => [:new, :create, :index, :preview] |
22 before_filter :find_project_from_association, :except => [:new, :index, :preview] | 22 before_filter :find_project_from_association, :except => [:new, :create, :index, :preview] |
23 before_filter :find_project, :only => [:new, :preview] | 23 before_filter :find_project, :only => [:new, :create, :preview] |
24 before_filter :authorize, :except => [:index, :preview] | 24 before_filter :authorize, :except => [:index, :preview] |
25 before_filter :find_optional_project, :only => :index | 25 before_filter :find_optional_project, :only => :index |
26 accept_key_auth :index | 26 accept_key_auth :index |
27 | 27 |
28 def index | 28 def index |
44 @comments.reverse! if User.current.wants_comments_in_reverse_order? | 44 @comments.reverse! if User.current.wants_comments_in_reverse_order? |
45 end | 45 end |
46 | 46 |
47 def new | 47 def new |
48 @news = News.new(:project => @project, :author => User.current) | 48 @news = News.new(:project => @project, :author => User.current) |
49 end | |
50 | |
51 def create | |
52 @news = News.new(:project => @project, :author => User.current) | |
49 if request.post? | 53 if request.post? |
50 @news.attributes = params[:news] | 54 @news.attributes = params[:news] |
51 if @news.save | 55 if @news.save |
52 flash[:notice] = l(:notice_successful_create) | 56 flash[:notice] = l(:notice_successful_create) |
53 redirect_to :controller => 'news', :action => 'index', :project_id => @project | 57 redirect_to :controller => 'news', :action => 'index', :project_id => @project |
58 else | |
59 render :action => 'new' | |
54 end | 60 end |
55 end | 61 end |
56 end | 62 end |
63 | |
64 def edit | |
65 end | |
57 | 66 |
58 def edit | 67 def update |
59 if request.post? and @news.update_attributes(params[:news]) | 68 if request.put? and @news.update_attributes(params[:news]) |
60 flash[:notice] = l(:notice_successful_update) | 69 flash[:notice] = l(:notice_successful_update) |
61 redirect_to :action => 'show', :id => @news | 70 redirect_to :action => 'show', :id => @news |
71 else | |
72 render :action => 'edit' | |
62 end | 73 end |
63 end | |
64 | |
65 def add_comment | |
66 @comment = Comment.new(params[:comment]) | |
67 @comment.author = User.current | |
68 if @news.comments << @comment | |
69 flash[:notice] = l(:label_comment_added) | |
70 redirect_to :action => 'show', :id => @news | |
71 else | |
72 show | |
73 render :action => 'show' | |
74 end | |
75 end | |
76 | |
77 def destroy_comment | |
78 @news.comments.find(params[:comment_id]).destroy | |
79 redirect_to :action => 'show', :id => @news | |
80 end | 74 end |
81 | 75 |
82 def destroy | 76 def destroy |
83 @news.destroy | 77 @news.destroy |
84 redirect_to :action => 'index', :project_id => @project | 78 redirect_to :action => 'index', :project_id => @project |