Created
October 26, 2017 18:59
-
-
Save romkaspb/a54ce83c446471accb70de35dcd8e528 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def show | |
url = request.original_url | |
if url.last == '?' | |
redirect_to url.chop and return | |
end | |
params[:name] = 'russia' if params[:name].blank? | |
@node = Node.find_by(name: params[:name]) | |
@sidebar = @node.articles.joins(:categories).published | |
.where(categories: {name: 'sidebar'}).to_a + @node.groups.all.to_a | |
@sidebar = @sidebar.sort_by{ |obj| obj.priority } if @sidebar.present? | |
@application_form = ApplicationForm.new | |
@articles = [] | |
if params[:name] == 'review-post' | |
if params[:id_or_urlname] # ApplicationForm id | |
review = ApplicationForm.published.find_by(id: params[:id_or_urlname]) | |
@articles = [review] if review | |
end | |
elsif params[:name] == 'reviews' | |
@articles = ApplicationForm.published.order(review_date: :desc) | |
elsif params[:name].in? %w(blog offers) | |
# url - ?cat_id[]=1&cat_id[]=2 | |
if params[:cat_id].blank? | |
if params[:name] == 'blog' | |
params[:cat_id] = [6] | |
elsif params[:name] == 'offers' | |
params[:cat_id] = [11] | |
end | |
end | |
category_ids = params[:cat_id].map{ |s| s.to_i_nn }.compact.uniq | |
@articles = Article.joins(:categories).published | |
.without_categories.with_categories(category_ids) | |
.uniq.order(created_at: :desc) | |
elsif params[:name].in? %w(russia blog-post offer-post) | |
# start page | |
if params[:id_or_urlname].blank? && params[:name] == 'russia' | |
# здесь бывает params[:reach_goal] | |
params[:id_or_urlname] = '2' | |
end | |
if params[:id_or_urlname] # Article id_or_urlname | |
if params[:id_or_urlname].first.to_i > 0 | |
article = Article.published.find_by(id: params[:id_or_urlname]) | |
if article | |
path_hash = { action: 'show', name: params[:name], | |
id_or_urlname: article.url_name } | |
if params[:reach_goal].present? | |
path_hash.merge!(reach_goal: params[:reach_goal]) | |
end | |
redirect_to(path_hash, status: 301) and return | |
end | |
else | |
article = Article.published.find_by(url_name: params[:id_or_urlname]) | |
@articles = [article] if article | |
end | |
end | |
end | |
if @articles.empty? | |
render_404 and return | |
else | |
store_location | |
end | |
respond_to do |format| | |
format.html | |
format.js | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
get ':name(/:id_or_urlname)' => 'nodes#show', :as => 'node' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment