Class: IshManager::NewsitemsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- IshManager::NewsitemsController
- Defined in:
- app/controllers/ish_manager/newsitems_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 27 def create @newsitem = Newsitem.new params[:newsitem].permit! @resource ||= City.find params[:city_id] if params[:city_id] @resource ||= City.find params[:newsitem][:city_id] if !params[:newsitem][:city_id].blank? # blank? required @resource ||= Site.find params[:site_id] if params[:site_id] @resource ||= Site.find params[:newsitem][:site_id] if !params[:newsitem][:site_id].blank? @resource ||= Tag.find params[:tag_id] if params[:tag_id] @resource ||= Tag.find params[:newsitem][:tag_id] if !params[:newsitem][:tag_id].blank? @resource ||= IshModels::UserProfile.find params[:newsitem][:user_profile_id] if !params[:newsitem][:user_profile_id].blank? @resource ||= ::Gameui::Map.find params[:newsitem][:map_id] if !params[:newsitem][:map_id].blank? @resource.newsitems << @newsitem :create_newsitem, @resource if params[:photo] photo = Photo.create :photo => params[:photo], :user_profile => current_user.profile @newsitem.photo = photo end url = case @resource.class.name when "City" edit_city_path( @resource.id ) when "Tag" @resource.site.touch tag_path( @resource.id ) when "Site" edit_site_path( @resource.id ) when "IshModels::UserProfile" user_profiles_path else root_path end flag = @newsitem.save && @resource.save if flag @resource.touch flash[:notice] = 'Success' redirect_to url else error = 'No Luck. ' + @newsitem.errors..to_s + " :: " + photo.errors..to_s flash[:alert] = error @sites = Site.list @cities = City.list render :action => :new end end |
#destroy ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 74 def destroy :destroy, Newsitem if params[:city_id] flag = City.find( params[:city_id] ).newsitems.find( params[:id] ).destroy url = edit_city_path( params[:city_id] ) end if profile_id = params[:user_profile_id] profile = IshModels::UserProfile.find profile_id flag = profile.newsitems.find( params[:id] ).destroy url = profile_path( profile_id ) end if params[:site_id] site = Site.find( params[:site_id] ) flag = site.newsitems.find( params[:id] ).destroy if flag site.touch end url = edit_site_path( params[:site_id] ) end if params[:tag_id] tag = Tag.find( params[:tag_id] ) flag = tag.newsitems.find( params[:id] ).destroy url = tag_path( params[:tag_id] ) end flash[:notice] = "Success? #{flag.inspect}" redirect_to request.referrer ? request.referrer : '/' end |
#edit ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 138 def edit out = Gallery.unscoped.where( :is_trash => false, :user_profile => current_user.profile ).order_by( :created_at => :desc ) @galleries_list = [['', nil]] + out.map { |item| [ "#{item.created_at.strftime('%Y%m%d')} #{item.name}", item.id ] } if params[:site_id] @site = Site.find params[:site_id] @newsitem = @site.newsitems.find( params[:id] ) end if params[:city_id] @city = City.find params[:city_id] @newsitem = @city.newsitems.find( params[:id] ) end :edit, @newsitem end |
#index ⇒ Object
154 155 156 157 158 159 160 |
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 154 def index @resource = Site.find( params[:site_id] ) if params[:site_id] @resource = City.find( params[:site_id] ) if params[:city_id] :newsitems_index, @resource @newsitems = @resource.newsitems end |
#new ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 4 def new @newsitem = Newsitem.new @cities_list = City.list @maps_list = ::Gameui::Map.list @sites_list = Site.list @tags_list = Tag.list if params[:city_id] @city = City.find params[:city_id] @newsitem.city = @city end if params[:site_id] @site = Site.find params[:site_id] @newsitem.site = @site end if params[:tag_id] @tag = Tag.unscoped.find params[:tag_id] @newsitem.tag = @tag end :new, @newsitem end |
#update ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 103 def update if params[:site_id] || params[:newsitem][:site_id] if params[:site_id] @site = Site.find params[:site_id] end if params[:newsitem][:site_id] @site = Site.find params[:newsitem][:site_id] end @site.touch @newsitem = @site.newsitems.find params[:id] url = edit_site_path( @site ) end if params[:city_id] @city = City.find params[:city_id] @newsitem = @city.newsitems.find params[:id] url = edit_city_path( @city ) end if params[:photo] photo = Photo.new :photo => params[:photo] photo.user_profile = current_user.profile @newsitem.photo = photo end :update, @newsitem flag = @newsitem.update_attributes params[:newsitem].permit! if flag flash[:notice] = 'Success' else flash[:alert] = "No Luck: #{@newsitem.errors.}" end redirect_to url end |