This commit is contained in:
Saurabh Bhatia 2014-04-11 16:26:34 +08:00
parent d2a696d610
commit 6a72f899d4
8 changed files with 35 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 %>

View File

@ -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 %>

View File

@ -1,2 +0,0 @@
<h1>Admin::AdImages#create</h1>
<p>Find me in app/views/admin/ad_images/create.html.erb</p>

View File

@ -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 %>

View File

@ -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 %>