# \[ANN\] New plugin - Personalise Site

**URL:** <https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944>\
**Category:** Rails\
**Created:** [September 30, 2007, 9:18pm UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944 "2007-09-30T21:18:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ss\_1982](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@ss\_1982](https://www.ruby-forum.com/u/ss_1982)\
**Post date:** [September 30, 2007, 9:18pm UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944/1 "2007-09-30T21:18:13Z")

</div>

This plugin provides helpers for your views that allow you to gain  
implicit data about the user browsing the site.

This is intended to be used to customise what the user see’s, maybe to  
improve usability or for cross-browser issues

Url: [http://www.railslodge.com/plugins/303-personalise-site](http://www.railslodge.com/plugins/303-personalise-site)  
SVN: [http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)

The following methods are available:

Returns the name of the browser the user is using  
\<%= def which\_browser? %\>

Returns the version number of the browser being used  
\<%=which\_browser\_version?%\>

Returns the name of the platform the user is using  
\<%= which\_platform? %\>

Nil is always returned if the data is unavailable

==== Example usage

An example below looks at the platform and outputs the right command to  
install this plugin

\<% if which\_platform? == ‘Windows’ -%\>  
ruby script/plugin install  
[http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
\<% elsif which\_platform? == ‘Mac’ -%\>  
./script/plugin install  
[http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
\<% else -%\>  
script/plugin install  
[http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
\<% end -%\>

# Info

Author: Scott S.  
License: MIT  
Date: 30-09-07

---

<div class="post-metadata">

**Author:** ![ss\_1982](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@ss\_1982](https://www.ruby-forum.com/u/ss_1982)\
**Post date:** [October 1, 2007, 1:23am UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944/2 "2007-10-01T01:23:01Z")

</div>

This is a stylistic nit pick, but typically methods that end in “?”  
return true or false rather than some other value. I would personally  
name the methods “user\_browser\_version” or “user\_platform” or  
something like that.

–Jeremy

On 9/30/07, Scott A S [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## The following methods are available: Nil is always returned if the data is unavailable ./script/plugin install Date: 30-09-07
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
[http://www.jeremymcanally.com/](http://www.jeremymcanally.com/)

My free Ruby e-book:  
[http://www.humblelittlerubybook.com/book/](http://www.humblelittlerubybook.com/book/)

My blogs:

> **[Site not found · DreamHost](http://www.mrneighborly.com/)**
>
> The owner of this domain has not yet uploaded their website.

[http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)

---

<div class="post-metadata">

**Author:** ![ss\_1982](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@ss\_1982](https://www.ruby-forum.com/u/ss_1982)\
**Post date:** [October 1, 2007, 9:30am UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944/3 "2007-10-01T09:30:13Z")

</div>

Hi Jeremy,

Thanks for your feedback,  
I have made the changes to remove the ‘?’ based on your comments.

Cheers,  
Scott S.

Jeremy McAnally wrote:

> This is a stylistic nit pick, but typically methods that end in “?”  
> return true or false rather than some other value. I would personally  
> name the methods “user\_browser\_version” or “user\_platform” or  
> something like that.
> 
> –Jeremy

---

<div class="post-metadata">

**Author:** ![ss\_1982](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@ss\_1982](https://www.ruby-forum.com/u/ss_1982)\
**Post date:** [October 2, 2007, 12:06am UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944/4 "2007-10-02T00:06:42Z")

</div>

Just some ideas…

On 10/1/07, Scott A S [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Jeremy,
> 
> Thanks for your feedback,  
> I have made the changes to remove the ‘?’ based on your comments.

You could also add some methods like the following:

running\_windows?  
running\_os\_x?

then your example becomes:

\<% if running\_windows? -%\>  
ruby script/plugin install  
[http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
\<% elsif running\_os\_x? -%\>  
./script/plugin install  
[http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
\<% else -%\>  
script/plugin install  
[http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
\<% end -%\>

Cheers,

---

<div class="post-metadata">

**Author:** ![ss\_1982](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@ss\_1982](https://www.ruby-forum.com/u/ss_1982)\
**Post date:** [October 3, 2007, 12:18am UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944/5 "2007-10-03T00:18:36Z")

</div>

Scott A S wrote:

> Yeah it’s a good idea, however this would require an extra 5 or 6  
> methods to replace the single which\_platform.
> 
> As I am very likley to be devleoping this one further, I really want to  
> keep the code as small and DRY as possible.

I dig it. If you really want methods like internet\_explorer? you could  
easily write your own. I probably will. =)

Thanks for the plugin, Scott.

- Rabbit

---

<div class="post-metadata">

**Author:** ![ss\_1982](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@ss\_1982](https://www.ruby-forum.com/u/ss_1982)\
**Post date:** [October 2, 2007, 11:43pm UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944/6 "2007-10-02T23:43:18Z")

</div>

Hi,

Yeah it’s a good idea, however this would require an extra 5 or 6  
methods to replace the single which\_platform.

As I am very likley to be devleoping this one further, I really want to  
keep the code as small and DRY as possible.

Scott

Michael G. wrote:

> You could also add some methods like the following:
> 
> running\_windows?  
> running\_os\_x?
> 
> then your example becomes:
> 
> \<% if running\_windows? -%\>  
> ruby script/plugin install  
> [http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
> \<% elsif running\_os\_x? -%\>  
> ./script/plugin install  
> [http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
> \<% else -%\>  
> script/plugin install  
> [http://svn.railslodge.com/svn/plugins/personalise\_site/](http://svn.railslodge.com/svn/plugins/personalise_site/)  
> \<% end -%\>
> 
> Cheers,

---

<div class="post-metadata">

**Author:** ![ss\_1982](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@ss\_1982](https://www.ruby-forum.com/u/ss_1982)\
**Post date:** [October 3, 2007, 5:58am UTC](https://www.ruby-forum.com/t/ann-new-plugin-personalise-site/115944/7 "2007-10-03T05:58:13Z")

</div>

What? Replace methods? No way. Just add some nice convenience methods to  
pretty up the views.

For example:

def running\_osx?  
which\_platform == ‘Mac’  
end

def running\_windows  
which\_platform == “Windows”  
end

Etc. You’re not replacing methods… you are adding a DSL to your  
plugin…  
which makes views much easier.

It also allows you to change the underlying implementation. For  
example…  
which\_platform might return “Windows” right now… but what if it  
returns  
win32 in some cases? It might also return something else in the future.

This is one reason why you access your params in a Rails application via  
params (a method) and not @params (an instance variable)

Nice plugin btw… have you submitted this to  
[agilewebdevelopment.com/plugins](http://agilewebdevelopment.com/plugins) yet?
