# Mini cms functionality within an app

**URL:** <https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791>\
**Category:** Rails\
**Created:** [January 22, 2008, 8:31am UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791 "2008-01-22T08:31:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 8:31am UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/1 "2008-01-22T08:31:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 1:15pm UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/2 "2008-01-22T13:15:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/3 "2008-01-22T13:37:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/4 "2008-01-22T14:10:35Z")

</div>

2008/1/22, bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 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.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 5:56pm UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/5 "2008-01-22T17:56:21Z")

</div>

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.](http://code.google.com/p/comatose-plugin/)_

On Jan 22, 2008 8:09 AM, Jean-FranÃ§ois TrÃ¢n [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Sounds interesting.
> 
> >

–  
Andrew K.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/6 "2008-01-22T20:26:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/7 "2008-01-22T21:45:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 22, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/mini-cms-functionality-within-an-app/126791/8 "2008-01-22T23:08:10Z")

</div>

2008/1/22, bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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.
