Skip to content

Instantly share code, notes, and snippets.

@aj07
Last active February 10, 2016 00:51
Show Gist options
  • Save aj07/794468a5f6f92ea63dfb to your computer and use it in GitHub Desktop.
Save aj07/794468a5f6f92ea63dfb to your computer and use it in GitHub Desktop.
<% @sub_section = @section.sub_sections.where(name: "banner").take if @section %>
<div id = "banner">
<div class="header" id="banner_background" style="<%= background_color(@section, 'banner') if @section %>;">
<% unless request.subdomain.present? %>
<div class="pull-right" style="">
<%if @sub_section.present? %>
<span class="btn btn-default btn-file">
Change Cover Image</i> <input type="file" name="coverImage" id="banner_image" class = "banner_image" data-section="banner" data-page="home" data-background="banner_background">
</span>
<span class="btn btn-default ">
<a href="javascript:void(0)" id="dark-color" class = "text_desing_image" data-section="banner" data-page="home" data-color="rgb(255, 255, 255)" data-background="news_text" >Light Text </a>
</span>
<span class="btn btn-default ">
<a href="javascript:void(0)" id="dark-color" class = "text_desing_image" data-section="banner" data-page="home" data-color="rgb(94, 97, 98)" data-background="news_text" >Dark Text </a>
</span>
<span class="btn btn-default"><a class="edit-text" style="background:none !important;color:#428bca">Edit Banner Text</a></span>
<% end %>
<span>
<% if @sub_section %>
<% if @sub_section.section_image.present? %>
<%= edit_section_image_btn("banner_image0hsu0banner_background0hsu0#{@sub_section.id}", "#{request.protocol}#{request.host_with_port}#{@sub_section.section_image_url(:thumb)}", "banner_edit_btn", false ) %>
<% elsif(!@sub_section.section_image.present?) %>
<%= edit_section_image_btn("banner_image0hsu0banner_background0hsu0#{@sub_section.id}", "#{request.protocol}#{request.host_with_port}", "banner_edit_btn", true) %>
<% end -%>
<% end -%>
</span>
</div>
<% end %>
<h3 class="heading text-center PadT2" >
<mark class="mark section-title-font news_text" id="banner_text" style="<%= text_color(@section, 'banner') if @section %>">
<% banner_text = "" %>
<% if @sub_section && @sub_section.contents.present? %>
<% banner_text = format_text(@sub_section.contents.try(:titleize).html_safe) %>
<%= banner_text %>
<% else %>
<% banner_text = "" %>
&nbsp;&nbsp;&nbsp;
<% end %>
<% unless request.subdomain.present? %>
<% if @sub_section.present? %>
<% end -%>
<% end %>
</mark>
<div class="txtBox">
<!-- <textarea rows="7" class="form-control"></textarea> -->
<%= form_tag create_banner_text_website_path(@website), remote: true, method: :get do %>
<%= cktext_area "banner", "content", :ckeditor => {:uiColor => "#999592"}, :value => banner_text, :required => :required %>
<a class="btn btn-default close-box">Cancel</a>
<%= submit_tag :Save , class:"btn btn-warning" %>
<% end %>
</div>
</h3>
<!-- <div class="col-md-6 center-block">
<ul class="nav-btn">
<li class="col-md-6"><a class="btn btn-default btn-orange">Volunteer Now</a></li>
<li class="col-md-6"><a class="btn btn-default btn-blue">Donate</a></li>
</ul>
</div> -->
</div>
</div>
class WebsitesController < BaseController
layout :get_layout, except: [:saved_template]
before_action :load_website
before_action :show_page, only: [:index, :about, :our_work, :our_impact, :gallery, :get_involved, :find_us, :donate]
def index; end
def about; end
def our_work; end
def our_impact; end
def gallery; end
def get_involved; end
def find_us; end
def donate; end
def create
redirect_to root_path
end
def save_font
# to update template fonts only and avoid to run unpublished call back
render json: { status: @website.update_columns(update_font_params) || @website.errors.full_messages }
end
def saved_template
current_ngo.websites.new(name: params[:template]).save
redirect_to websites_path(template: params[:template]), notice: "Your layout successfully saved."
end
def upload_banner_image
website = Website.find(params[:id])
if website
@sub_section = website.sections.find_by_name(params[:section]).sub_sections.where(name: params[:subsection]).take
@sub_section.section_image = params[:banner_image]
if @sub_section.save
render json: {banner_image_url: s3_uploaded_url(@sub_section.section_image.current_path), success: true }
else
render json: {banner_image_url: nil, success: false }
end
end
end
def change_color_text
website = Website.find(params[:id])
if website
@sub_section = website.sections.find_by_name(params[:section]).sub_sections.where(name: params[:subsection]).take
@sub_section.text_color = params[:color]
if @sub_section.save
render json: {text_color: @sub_section.text_color, success: true }
else
render json: {text_color: nil, success: false }
end
end
end
def create_banner_text
website = Website.find(params[:id])
if website
@sub_section = website.sections.find_by_name("home").sub_sections.where(name: "banner").take
@sub_section.contents = params[:banner]["content"]
@sub_section.save
render :layout => false
end
end
def change_section_background
website = Website.find(params[:id])
if website
@sub_section = website.sections.find_by_name(params[:page]).sub_sections.where(name: params[:type]).take
@sub_section.contents = params[:color]
@sub_section.remove_section_image!
if @sub_section.save
render :json => { success: true, type: params[:type], background_color: @sub_section.contents }
else
render :json => { success: false }
end
end
end
#A method for updating the icons of subsections
def change_subsection_icon
website = Website.find(params[:id])
if website
@sub_section = website.sections.find_by_name(params[:page]).sub_sections.where(name: params[:type]).take
@sub_section.contents = params[:color]
@sub_section.remove_section_image!
if @sub_section.save
render :json => { success: true, type: params[:type], background_color: @sub_section.contents }
else
render :json => { success: false }
end
end
end
def edit_banner
@website = Website.find(params[:id])
@section = @website.sections.find_by_name("home")
end
def crop_image
@section = Section.find(params[:id])
@section.remote_section_image_url = params[:image_url]
@section.save
render :json => {image_url: s3_uploaded_url(@section.section_image.current_path(:thumb)) }
end
private
def check_mysite
redirect_to root_path unless current_ngo.mysite
end
def get_layout
"#{@website.name}_layout"
end
def permit_section
params.require(:section).permit(:crop_x, :crop_y, :crop_w, :crop_h)
end
def load_website
@website ||= current_ngo.websites.where(name: params[:template]).first_or_initialize
@section = @website.sections.find_by_name(page)
end
def show_page
@site_data = ParseNgoData.new(session[:ngo_id], page).to_json
# render json: @site_data
# return
render template: "#{@website.name}/#{page}"
end
def site_data_value
@site_data
end
helper_method :site_data_value
def page
params[:action].eql?("index") ? 'home' : params[:action]
end
def update_font_params
params.permit(:title_font, :sub_title_font, :text_font)
end
end
Showing /home/ankit/copy/app/views/layouts/_template_1_index_banner.html.erb where line #48 raised:
No route matches {:action=>"create_banner_text", :controller=>"websites", :id=>nil} missing required keys: [:id]
NGOTemplate::Application.routes.draw do
resources :abouticons, only: [:index, :new, :create, :destroy]
mount Ckeditor::Engine => '/ckeditor'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
concern :headers do
get :about
get :our_work
get :our_impact
get :gallery
get :get_involved
get :find_us
get :donate
end
constraints(SubdomainBlank) do
root :to => 'home#index'
resources :websites, only: [:index, :create] do
collection do
delete :destroy_mysite
get :publish_website
get :saved_template
concerns :headers
put "/:template/save_font", to: "websites#save_font"
end
member do
post :upload_banner_image
get :create_banner_text
get :change_section_background
get :change_color_text
end
end
resources :mysites do
get :refresh_ngo, on: :collection
end
end
# match 'mysites' => 'mysites#index', via: :get, :constraints => { :subdomain => /.+/ }
constraints(SubdomainPresent) do
match "/", to: 'published_sites#index', via: :get
resources :published_sites do
collection do
concerns :headers
end
end
# resources :websites, only: [:index, :create] do
# collection do
# delete :destroy_mysite
# get :publish_website
# get :saved_template
# end
# member do
# post :upload_banner_image
# get :create_banner_text
# get :change_section_background
# end
# end
# resources :mysites do
# post :upload_banner_image
# get :create_banner_text
# get :change_section_background
# get :edit_banner
# end
end
get 'crop_image/:id' => "websites#crop_image"
post "application/partners_status" => "application#partners_status"
post "application/partners_update" => "application#partners_update"
post "application/about_page_update" => "application#about_page_update"
post "application/our_work_update" => "application#our_work_update"
post "application/about_page_return" => "application#about_page_return"
post "abouticons/destroy" => "abouticons#destroy"
post "application/layout_update" => "application#layout_update"
post "application/layout_hide" => "application#layout_hide"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment