Class: SearchKeywordsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SearchKeywordsController
- Defined in:
- app/controllers/search_keywords_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #newsupdate ⇒ Object
- #postnews ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/search_keywords_controller.rb', line 47 def create @search_keyword = SearchKeyword.new(params[:search_keyword]) @search_keyword.user = current_user if @search_keyword.save flash[:notice] = t :keyword_creation_success_flash redirect_to @search_keyword else render :action => 'new' end end |
#destroy ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/search_keywords_controller.rb', line 81 def destroy @search_keyword = get_keyword_for_current_user(params[:id]) if @search_keyword.nil? then flash[:notice] = t :access_denied_flash redirect_to :controller => 'site', :action => 'index' else @search_keyword.destroy flash[:notice] = t :keyword_destroy_success_flash redirect_to search_keywords_url end end |
#edit ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/controllers/search_keywords_controller.rb', line 58 def edit @search_keyword = get_keyword_for_current_user(params[:id]) if @search_keyword.nil? flash[:notice] = t :keyword_update_denied_flash redirect_to :controller => 'site', :action => 'index' end end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/search_keywords_controller.rb', line 9 def index @search_keyword = SearchKeyword.new if current_user.has_role?(:admin) watched_user = params[:user_id] ? User.find_by_username(params[:user_id]) : current_user else watched_user = current_user flash[:notice] = t :access_denied_flash \ if params[:user_id] and (current_user.username != params[:user_id]) end @search_keyword.user = watched_user @search_keywords = watched_user.search_keywords end |
#new ⇒ Object
42 43 44 45 |
# File 'app/controllers/search_keywords_controller.rb', line 42 def new @search_keyword = SearchKeyword.new @search_keyword.user = current_user end |
#newsupdate ⇒ Object
22 23 24 25 26 |
# File 'app/controllers/search_keywords_controller.rb', line 22 def newsupdate page = (params[:page] || 1).to_i @articles = current_user.collect_recent_articles.paginate(:page => page, :per_page => Article.per_page) end |
#postnews ⇒ Object
28 29 30 31 32 |
# File 'app/controllers/search_keywords_controller.rb', line 28 def postnews flash[:notice] = current_user.post_recent_news ? \ t(:news_were_posted_flash) : t(:no_news_were_posted_flash) redirect_to :action => 'newsupdate' end |
#show ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/controllers/search_keywords_controller.rb', line 34 def show @search_keyword = get_keyword_for_current_user(params[:id]) if @search_keyword.nil? then flash[:notice] = t :keyword_does_not_exist_flash redirect_to :controller => 'site', :action => 'index' end end |
#update ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/search_keywords_controller.rb', line 66 def update @search_keyword = get_keyword_for_current_user(params[:id]) if @search_keyword.nil? then flash[:notice] = t :keyword_update_denied_flash redirect_to :controller => 'site', :action => 'index' return end if @search_keyword.update_attributes(params[:search_keyword]) flash[:notice] = t :keyword_update_success_flash redirect_to @search_keyword else render :action => 'edit' end end |