diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 72aee98..17a626a 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -10,12 +10,13 @@ class Admin::AdBannersController < ApplicationController end def new - @banner = Banner.new + @ad_banner = Banner.new end def create - @banner = Banner.new(banner_params) - @banner.save + @ad_banner = Banner.new(banner_params) + @ad_banner.save + render "index" end private diff --git a/app/controllers/admin/ad_images_controller.rb b/app/controllers/admin/ad_images_controller.rb index 6c31e0e..2a1107a 100644 --- a/app/controllers/admin/ad_images_controller.rb +++ b/app/controllers/admin/ad_images_controller.rb @@ -5,17 +5,19 @@ class Admin::AdImagesController < ApplicationController def new @ad_image = AdImage.new + @ad_banners = Banner.all end def create @ad_image = AdImage.new(ad_image_params) @ad_image.save + redirect_to admin_ad_images_path end private # Never trust parameters from the scary internet, only allow the white list through. def ad_image_params - params.require(:ad_image).permit(:weight, :out_link, :link_open, :file, :file_cache, title_translations: [:en, :zh_tw], context_translations: [:en, :zh_tw]) + params.require(:ad_image).permit(:weight, :out_link, :link_open, :file, :file_cache, :banner_id, title_translations: [:en, :zh_tw], context_translations: [:en, :zh_tw]) end end \ No newline at end of file diff --git a/app/models/ad_image.rb b/app/models/ad_image.rb index b178565..76a7b9a 100644 --- a/app/models/ad_image.rb +++ b/app/models/ad_image.rb @@ -11,7 +11,7 @@ class AdImage field :link_open, type: String LINK_OPEN_TYPES = ["local", "new_window"] - belongs_to :ad_banner + belongs_to :banner validates :file, :presence => true diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index 8fe1508..42475b2 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -1,2 +1,8 @@ -

Admin::AdBanners#index

-

Find me in app/views/admin/ad_banners/index.html.erb

+<% @ad_banners.each do |a|%> + <%= a.title %> + <%= a.ad_fx %> + <%= a.height %> + <%= a.width %> + <%= a.speed %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/ad_banners/new.html.erb b/app/views/admin/ad_banners/new.html.erb index e69de29..f74435d 100644 --- a/app/views/admin/ad_banners/new.html.erb +++ b/app/views/admin/ad_banners/new.html.erb @@ -0,0 +1,15 @@ +<%= form_for(@ad_banner, url: {action: "create"}) do |f| %> + Title <%= f.text_field :title %> + + Timeout <%= f.text_field :timeout %> + + Width <%= f.text_field :width %> + + Height <%= f.text_field :height %> + + Speed <%= f.text_field :speed %> + + Ad Fx <%= f.text_field :ad_fx %> + + <%= f.submit "Create Banner" %> +<% end %> diff --git a/app/views/admin/ad_images/create.html.erb b/app/views/admin/ad_images/create.html.erb deleted file mode 100644 index 85276a6..0000000 --- a/app/views/admin/ad_images/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Admin::AdImages#create

-

Find me in app/views/admin/ad_images/create.html.erb

diff --git a/app/views/admin/ad_images/index.html.erb b/app/views/admin/ad_images/index.html.erb index b792cef..17f04e3 100644 --- a/app/views/admin/ad_images/index.html.erb +++ b/app/views/admin/ad_images/index.html.erb @@ -1,4 +1,5 @@ <% @ad_images.each do |a|%> <%= a.title %> - <%=image_tag(a.file.url)%> + <%= a.banner.title%> + <%=image_tag(a.file.url(:thumb))%> <% end %> \ No newline at end of file diff --git a/app/views/admin/ad_images/new.html.erb b/app/views/admin/ad_images/new.html.erb index 1ce0de4..fb78475 100644 --- a/app/views/admin/ad_images/new.html.erb +++ b/app/views/admin/ad_images/new.html.erb @@ -18,5 +18,7 @@ <%= f.hidden_field :file_cache %>

+ <%= f.select :banner_id, @ad_banners.collect{|t| [ t.title, t.id ]} %> + <%= f.submit "Create Banner Image" %> <% end %> \ No newline at end of file