Add announcement model
This commit is contained in:
1 parent
62602940ed
commit
4807066c68
12 files changed
+182
-278
No files matched your search
@@ -0,0 +1,85 @@
|
||||
class AnnouncementsController < ApplicationController
|
||||
# GET /announcements
|
||||
# GET /announcements.xml
|
||||
def index
|
||||
@announcements = Announcement.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @announcements }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /announcements/1
|
||||
# GET /announcements/1.xml
|
||||
def show
|
||||
@announcement = Announcement.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.xml { render :xml => @announcement }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /announcements/new
|
||||
# GET /announcements/new.xml
|
||||
def new
|
||||
@announcement = Announcement.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @announcement }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /announcements/1/edit
|
||||
def edit
|
||||
@announcement = Announcement.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /announcements
|
||||
# POST /announcements.xml
|
||||
def create
|
||||
@announcement = Announcement.new(params[:announcement])
|
||||
|
||||
respond_to do |format|
|
||||
if @announcement.save
|
||||
flash[:notice] = 'Announcement was successfully created.'
|
||||
format.html { redirect_to(@announcement) }
|
||||
format.xml { render :xml => @announcement, :status => :created, :location => @announcement }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /announcements/1
|
||||
# PUT /announcements/1.xml
|
||||
def update
|
||||
@announcement = Announcement.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @announcement.update_attributes(params[:announcement])
|
||||
flash[:notice] = 'Announcement was successfully updated.'
|
||||
format.html { redirect_to(@announcement) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /announcements/1
|
||||
# DELETE /announcements/1.xml
|
||||
def destroy
|
||||
@announcement = Announcement.find(params[:id])
|
||||
@announcement.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(announcements_url) }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,8 +5,11 @@ class PagesController < ApplicationController
|
||||
def show
|
||||
@page = Page.find(:first, :conditions => { :name => params[:page_name], :is_published => true })
|
||||
|
||||
if @page && @page.external_link
|
||||
if @page && !@page.external_link.blank?
|
||||
redirect_to @page.external_link
|
||||
elsif @page && @page.use_engine
|
||||
#model_class = Kernel.const_get( "Announcement" ) # page.use_engine
|
||||
redirect_to announcements_path
|
||||
elsif @page
|
||||
@layout = @page.layout
|
||||
@page_content = Liquid::Template.parse(@page.content).render
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
module AnnouncementsHelper
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class Announcement < CouchFoo::Base
|
||||
|
||||
property :title, String
|
||||
property :content, String
|
||||
|
||||
validates_presence_of :title
|
||||
|
||||
def self.load
|
||||
# hmm.... but one module will has many pages
|
||||
end
|
||||
|
||||
def to_liquid
|
||||
{ :title => self.title, :content => self.content }
|
||||
end
|
||||
|
||||
end
|
||||
+1
-1
@@ -5,7 +5,7 @@ class Page < CouchFoo::Base
|
||||
property :content, String
|
||||
property :layout_id, String
|
||||
property :layout_name, String
|
||||
property :load_model, String
|
||||
property :use_engine, String
|
||||
property :external_link, String
|
||||
property :position, Integer
|
||||
property :is_published, Boolean
|
||||
|
||||
@@ -21,4 +21,9 @@
|
||||
<p>
|
||||
<%= f.label :external_link, "External Link" %>
|
||||
<%= f.text_field :external_link %>
|
||||
</p>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :use_engine, "Use Engine" %>
|
||||
<%= f.text_field :use_engine %>
|
||||
<p>
|
||||
@@ -0,0 +1,22 @@
|
||||
<h1>Editing announcement</h1>
|
||||
|
||||
<% form_for(@announcement) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :title, "Title" %>
|
||||
<%= f.text_field :title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :content, "Content" %>
|
||||
<%= f.text_area :content %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.submit 'Update' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Show', @announcement %> |
|
||||
<%= link_to 'Back', announcements_path %>
|
||||
@@ -0,0 +1,18 @@
|
||||
<h1>Listing announcements</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
</tr>
|
||||
|
||||
<% @announcements.each do |announcement| %>
|
||||
<tr>
|
||||
<td><%= link_to 'Show', announcement %></td>
|
||||
<td><%= link_to 'Edit', edit_announcement_path(announcement) %></td>
|
||||
<td><%= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New announcement', new_announcement_path %>
|
||||
@@ -0,0 +1,21 @@
|
||||
<h1>New announcement</h1>
|
||||
|
||||
<% form_for(@announcement) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :title, "Title" %>
|
||||
<%= f.text_field :title %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :content, "Content" %>
|
||||
<%= f.text_area :content %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.submit 'Create' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', announcements_path %>
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
<%= link_to 'Edit', edit_announcement_path(@announcement) %> |
|
||||
<%= link_to 'Back', announcements_path %>
|
||||
Reference in new issue
Block a user