Ad Image
This commit is contained in:
parent
d2a696d610
commit
6a72f899d4
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,2 +1,8 @@
|
|||
<h1>Admin::AdBanners#index</h1>
|
||||
<p>Find me in app/views/admin/ad_banners/index.html.erb</p>
|
||||
<% @ad_banners.each do |a|%>
|
||||
<%= a.title %>
|
||||
<%= a.ad_fx %>
|
||||
<%= a.height %>
|
||||
<%= a.width %>
|
||||
<%= a.speed %>
|
||||
|
||||
<% end %>
|
|
@ -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 %>
|
|
@ -1,2 +0,0 @@
|
|||
<h1>Admin::AdImages#create</h1>
|
||||
<p>Find me in app/views/admin/ad_images/create.html.erb</p>
|
|
@ -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 %>
|
|
@ -18,5 +18,7 @@
|
|||
<%= f.hidden_field :file_cache %>
|
||||
</p>
|
||||
|
||||
<%= f.select :banner_id, @ad_banners.collect{|t| [ t.title, t.id ]} %>
|
||||
|
||||
<%= f.submit "Create Banner Image" %>
|
||||
<% end %>
|
Loading…
Reference in New Issue