Mini cms functionality within an app

I need a sort of mini cms function in my app, allow a user to alter the
content of the site (nothin too sophisticated). Just want them to be
able to alter “fragments” of content on the pages.

I do it like this and I know it’s not the best way, can someone tell me
a better way (a simple example if possible), I believe I need something
in my model to allow me to stop rpeating myself and stop all the typing
!..


class WelcomeController < ApplicationController

def index
@blog_entry = BlogEntry.most_recent
@content = PageContent.find(:first, :conditions => “title = ‘home’”)
end

def enquiries
@content = PageContent.find(:first, :conditions => “title =
‘enquiries’”)
redirect_to :controller => “enquiries”, :action => “new”
end

def euroblog
@content = PageContent.find(:first, :conditions => “title =
‘euroblog’”)

@articles = BlogEntry.all_blog_entries

end

def people
@content = PageContent.find(:first, :conditions => “title =
‘people’”)
end

def gallery
@content = PageContent.find(:first, :conditions => “title =
‘gallery’”)

@gallery_entries = GalleryItem.all_gallery_entries

end

def courses
@content = PageContent.find(:first, :conditions => “title =
‘courses’”)

@courses = Course.all_courses

end

def accommodation
@content = PageContent.find(:first, :conditions => “title =
‘accommodation’”)
end

def excursions
@content = PageContent.find(:first, :conditions => “title =
‘excursions’”)
end

def bournemouth
@content = PageContent.find(:first, :conditions => “title =
‘bournemouth’”)
end

def prices
@content = PageContent.find(:first, :conditions => “title =
‘prices’”)

@courses = Course.all_courses

end

def agents
@content = PageContent.find(:first, :conditions => “title =
‘agents’”)
end

def find_us
@content = PageContent.find(:first, :conditions => “title =
‘find_us’”)
end

def opening_times
@content = PageContent.find(:first, :conditions => “title =
‘opening_times’”)
end

def visas
@content = PageContent.find(:first, :conditions => “title =
‘visas’”)
end

def terms
@content = PageContent.find(:first, :conditions => “title =
‘terms’”)
end
end

2008/1/22, bingo bob :

I need a sort of mini cms function in my app, allow a user to
alter the content of the site (nothin too sophisticated). Just
want them to be able to alter “fragments” of content on the pages.

I do it like this and I know it’s not the best way, can
someone tell me a better way (a simple example if possible),
I believe I need something in my model to allow me to stop
rpeating myself and stop all the typing !..

Using ActionController::Base#action_name in a before_filter
can be your friend.

– Jean-François.

Jean-François Trân wrote:

2008/1/22, bingo bob :

I need a sort of mini cms function in my app, allow a user to
alter the content of the site (nothin too sophisticated). Just
want them to be able to alter “fragments” of content on the pages.

I do it like this and I know it’s not the best way, can
someone tell me a better way (a simple example if possible),
I believe I need something in my model to allow me to stop
rpeating myself and stop all the typing !..

Using ActionController::Base#action_name in a before_filter
can be your friend.

– Jean-Fran篩s.

Ok, can you elaborate?

Sounds interesting.

2008/1/22, bingo bob [email protected]:

Using ActionController::Base#action_name in a before_filter
can be your friend.

– Jean-François.

Ok, can you elaborate?

Sounds interesting.

class WelcomeController < ApplicationController
before_filter :find_content, :except => [ :index ]

def agents
end

private
def find_content
@content = PageContent.find_first_by_title(action_name)
end
end

Not tested, but you get the idea.

– Jean-François.

you might also want to have a look at comatose - it doesn’t do exactly
what
you are asking for out of the box, but it is a nice plugin cms to add to
a
site.

Google Code Archive - Long-term storage for Google Code Project Hosting.

On Jan 22, 2008 8:09 AM, Jean-François Trân [email protected]
wrote:

Sounds interesting.


Andrew K.

jean francois idea seems perfect…it wont work for me though!

can someone have a look at the code…

the error i get it…

undefined method `find_first_by_title’ for #Class:0x2ad6518

confused…BB


class WelcomeController < ApplicationController

before_filter :find_content, :except => [ :index ]

def index
@blog_entry = BlogEntry.most_recent
# # @content = PageContent.find(:first, :conditions => “title =
‘home’”)
end

def enquiries
## @content = PageContent.find(:first, :conditions => “title =
‘enquiries’”)
redirect_to :controller => “enquiries”, :action => “new”
end

def euroblog
## @content = PageContent.find(:first, :conditions => “title =
‘euroblog’”)

@articles = BlogEntry.all_blog_entries

end

def people
## @content = PageContent.find(:first, :conditions => “title =
‘people’”)
end

def gallery
## @content = PageContent.find(:first, :conditions => “title =
‘gallery’”)

@gallery_entries = GalleryItem.all_gallery_entries

end

def courses
# @content = PageContent.find(:first, :conditions => “title =
‘courses’”)

@courses = Course.all_courses

end

def accommodation
# @content = PageContent.find(:first, :conditions => “title =
‘accommodation’”)
end

def excursions
# @content = PageContent.find(:first, :conditions => “title =
‘excursions’”)
end

def bournemouth
# @content = PageContent.find(:first, :conditions => “title =
‘bournemouth’”)
end

def prices
# @content = PageContent.find(:first, :conditions => “title =
‘prices’”)

@courses = Course.all_courses

end

def agents
# @content = PageContent.find(:first, :conditions => “title =
‘agents’”)
end

def find_us
# @content = PageContent.find(:first, :conditions => “title =
‘find_us’”)
end

def opening_times
# @content = PageContent.find(:first, :conditions => “title =
‘opening_times’”)
end

def visas
# @content = PageContent.find(:first, :conditions => “title =
‘visas’”)
end

def terms
# @content = PageContent.find(:first, :conditions => “title =
‘terms’”)
end

private
def find_content
@content = PageContent.find_first_by_title(action_name)
# @content = PageContent.find(:first, :conditions => “title =
‘terms’”)
end

end

anyone help, i think it should work, clearly my syntax is wrong?

2008/1/22, bingo bob [email protected]:

jean francois idea seems perfect…it wont work for me though!

can someone have a look at the code…

the error i get it…

undefined method `find_first_by_title’ for #Class:0x2ad6518

oops, it should be @content = PageContent.find_by_title(action_name)

– Jean-François.