Ruby on Rails 3.2.3, Ruby 1.9
Here is the an action of a controller in Ruby on Rails. There are two conditions: if parameter :tag_name
exists and if it doesn't. How do I simplify this?
def page
page = params[:page_id]
if !params[:tag_name].nil?
@paged_articles = articles.search(:page=>page, :tags=>params[:tag_name], :per_page=>@@articles_per_page)
else
@paged_articles = articles.search(:page=>page, :per_page=>@@articles_per_page)
end
if @paged_articles.size>0
page.succ!
if !params[:tag_name].nil?
has_more_articles = articles.search(:page=>page, :tags=>params[:tag_name], :per_page=>@@articles_per_page)
else
has_more_articles = articles.search( :page=>page, :per_page=>@@articles_per_page)
end
if has_more_articles.size>0
if !params[:tag_name].nil?
@next_page_url = url_for(:controller =>:home, :action => :page, :tags=>params[:tag_name], :page_id=> page)
else
@next_page_url = url_for(:controller =>:home, :action => :page, :page_id=> page)
end
else
@next_page_url = nil
end
respond_to() do |format|
format.js
end
end
end
page.succ!
do? – Speransky Danil Aug 2 '12 at 8:17