diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 4790ebc..279e8d6 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -18,10 +18,8 @@ def index # GET /categories/1.xml def show @category = Category.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.xml { render :xml => @category } + if @category.redirect_to_content_page and params[:no_redirect].blank? + redirect_to @category.redirect_to_content_page end end @@ -55,7 +53,7 @@ def update respond_to do |format| if @category.update_attributes(params[:category]) flash[:notice] = 'Category was successfully updated.' - format.html { redirect_to(@category) } + format.html { redirect_to(category_path(@category, :no_redirect => 1)) } format.xml { head :ok } else format.html { render :action => "edit" } diff --git a/app/models/category.rb b/app/models/category.rb index bf70ac9..7f79723 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -3,6 +3,8 @@ class Category < ActiveRecord::Base has_many :blog_posts, :class_name => 'Blog::Post' belongs_to :parent, :class_name => 'Category' has_many :children, :class_name => 'Category', :foreign_key => 'parent_id' + belongs_to :redirect_to_content_page, :class_name => 'ContentPage', + :foreign_key => 'redirect_to_content_page_id' validates_presence_of :name validates_uniqueness_of :name searchable_by :name diff --git a/app/views/categories/_list.html.erb b/app/views/categories/_list.html.erb index 435f0c9..2ef9f5d 100644 --- a/app/views/categories/_list.html.erb +++ b/app/views/categories/_list.html.erb @@ -2,7 +2,7 @@ <% categories.each do |category| -%>
Category: <%= f.text_field :name %>
Parent: <%= f.select :parent_id, @categories.map {|c| [c.name, c.id]}, :include_blank => true %>
+ instead of showing a boring table when you land on this category page, you can redirect to an actual content page
+ Redirect to: <%= f.select :redirect_to_content_page_id,
+ ContentPage.order("name").map {|cp| [cp.name, cp.id]},
+ :include_blank => true %>
<%= f.submit 'save category' %>
+ Note: This category page redirects to: + <%= link_to @category.redirect_to_content_page.name, + @category.redirect_to_content_page %> +
+ <% else %> +Want this page to redirect to a real page?
+ <% end %> + <%= form_for(@category) do |f| %> ++ Redirect to: <%= f.select :redirect_to_content_page_id, + ContentPage.order("name").map {|cp| [cp.name, cp.id]}, + :include_blank => true %> + <%= f.submit 'set' %> +
+ <% end %> +