主页页面设为主页或取消首页后跳转至主页列表、已设为主页的始终显示在前方

This commit is contained in:
cxt 2016-10-19 19:38:44 +08:00
parent bebff7b24a
commit 85f489eb97
3 changed files with 23 additions and 8 deletions

View File

@ -6,7 +6,12 @@ class HomepagesController < ApplicationController
@b_sort = params[:sort] || 1 @b_sort = params[:sort] || 1
@b_sort = @b_sort.to_i == 1 ? 2 : 1 @b_sort = @b_sort.to_i == 1 ? 2 : 1
sort_type = @b_sort == 1 ? "asc" : "desc" sort_type = @b_sort == 1 ? "asc" : "desc"
@articles = @user.homepage.article_homepages.reorder("updated_at #{sort_type}") if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at #{sort_type}")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at #{sort_type}").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
@limit = 20 @limit = 20
@is_remote = true @is_remote = true
@atta_count = @articles.count @atta_count = @articles.count
@ -30,14 +35,19 @@ class HomepagesController < ApplicationController
def set_homepage def set_homepage
@homepage = Homepage.find(params[:id]) @homepage = Homepage.find(params[:id])
@homepage.update_attribute(:article_id, params[:article_id]) @homepage.update_attribute(:article_id, params[:article_id])
@articles = @user.homepage.article_homepages.reorder("updated_at desc") if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at desc")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at desc").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
@limit = 20 @limit = 20
@is_remote = true @is_remote = true
@atta_count = @articles.count @atta_count = @articles.count
@atta_pages = Paginator.new @atta_count, @limit, 1 @atta_pages = Paginator.new @atta_count, @limit, 1
@articles = paginateHelper @articles,@limit @articles = paginateHelper @articles,@limit
if params[:show] if params[:show]
redirect_to homepage_user_path(@user.id) redirect_to user_homepages_path(:user_id => @user.id)
return return
else else
respond_to do |format| respond_to do |format|
@ -49,14 +59,19 @@ class HomepagesController < ApplicationController
def cancel_homepage def cancel_homepage
@homepage = Homepage.find(params[:id]) @homepage = Homepage.find(params[:id])
@homepage.update_attribute(:article_id, nil) @homepage.update_attribute(:article_id, nil)
@articles = @user.homepage.article_homepages.reorder("updated_at desc") if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at desc")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at desc").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
@limit = 20 @limit = 20
@is_remote = true @is_remote = true
@atta_count = @articles.count @atta_count = @articles.count
@atta_pages = Paginator.new @atta_count, @limit, 1 @atta_pages = Paginator.new @atta_count, @limit, 1
@articles = paginateHelper @articles,@limit @articles = paginateHelper @articles,@limit
if params[:show] if params[:show]
redirect_to user_homepage_article_homepage_path(:user_id=>@user.id, :homepage_id=>@homepage.id,:id=>params[:article_id].to_i) redirect_to user_homepages_path(:user_id => @user.id)
return return
else else
respond_to do |format| respond_to do |format|

View File

@ -8,8 +8,8 @@
<div class="cl"></div> <div class="cl"></div>
<div class="category"> <div class="category">
<span class="grayTxt">排序:</span> <span class="grayTxt">排序:</span>
<%= link_to "时间", {:controller => 'homepages', :action => 'index', :id =>@user, :sort => @b_sort}, :class => "sortTxt", :remote => true %> <%= link_to "时间", {:controller => 'homepages', :action => 'index', :user_id =>@user.id, :sort => @b_sort}, :class => "sortTxt", :remote => true %>
<%= link_to "", {:controller => 'homepages', :action => 'index', :id =>@user, :sort => @b_sort}, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %> <%= link_to "", {:controller => 'homepages', :action => 'index', :user_id =>@user.id, :sort => @b_sort}, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<div class="bloglistbox"> <div class="bloglistbox">

View File

@ -36,7 +36,7 @@
<li>地区&nbsp;:&nbsp;</li> <li>地区&nbsp;:&nbsp;</li>
<li>邮件通知&nbsp;:&nbsp;</li> <li>邮件通知&nbsp;:&nbsp;</li>
<!--<li>个人签名&nbsp;:&nbsp;</li>--> <!--<li>个人签名&nbsp;:&nbsp;</li>-->
<li>个人简介&nbsp;:&nbsp;</li> <li>个人主页&nbsp;:&nbsp;</li>
<li>&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;</li>
</ul> </ul>
<ul class="setting_right "> <ul class="setting_right ">