|
- class HomesController < ApplicationController
- layout 'base_introduce'
-
- before_filter :find_home, :except => [:index, :new, :create, :partners, :news]
-
- def index
- @home = Home.includes(:banners, :cover => [:file]).first
- @dynamic_news = DynamicNew.desc.limit(4)
-
- @companies = WebFooterCompany.dedicators
- @partners = WebFooterCompany.opensources
-
- @first_companies_group = Array(@companies.slice(0, 5))
- @second_companies_group = Array(@companies.slice(5, 8))
- @third_companies_group = Array(@companies.slice(13, 5))
-
- fresh_when :last_modified => @home.updated_at.utc, :etag => [@home, @companies, @partners, @slide_wall, @first_companies_group, @second_companies_group, @third_companies_group]
- end
-
- def partners
- @companies = WebFooterCompany.where(key: ['opensource', 'dedicator']).group_by(&:key).sort { |a, b| b[0]<=>a[0] }
- end
-
- def news
- scope = DynamicNew.desc
- @dynamic_news_count = scope.count
-
- @dynamic_news = paginateHelper scope, 15
- @page = (params['page'] || 1).to_i - 1
-
- respond_to do |format|
- format.js
- format.html
- end
- end
-
- # GET /homes/1
- # GET /homes/1.json
- def show
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @home }
- end
- end
-
- # GET /homes/new
- # GET /homes/new.json
- def new
- @home = Home.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @home }
- end
- end
-
- # GET /homes/1/edit
- def edit
- end
-
- # POST /homes
- # POST /homes.json
- def create
- @home = Home.new(params[:home])
-
- respond_to do |format|
- if @home.save
- format.html { redirect_to @home, notice: 'Home was successfully created.' }
- format.json { render json: @home, status: :created, location: @home }
- else
- format.html { render action: "new" }
- format.json { render json: @home.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # PUT /homes/1
- # PUT /homes/1.json
- def update
-
- respond_to do |format|
- if @home.update_attributes(params[:home])
- format.html { redirect_to @home, notice: 'Home was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @home.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /homes/1
- # DELETE /homes/1.json
- def destroy
- @home.destroy
-
- respond_to do |format|
- format.html { redirect_to homes_url }
- format.json { head :no_content }
- end
- end
-
- private
- def find_home
- @home = Home.find_by_frendly_id! params[:id]
- end
- end
|