Topic: Registering - number of visitors

I don't know if this thread would belong under this category (please feel free to move it under the proper category).

My application deals with 'users' (has_one) 'profiles' so basically i want to keep track of the number of visitors of a profile.

so i wanted to know - what is the most used approach for this kind of requirement? - do i maintain a visitors field in profiles table and update it every time a user visits the profile or how else if any other way - plus the app is also keeping track of last login or 'login history'

any thoughts?

radical vision fuels disruptive technologies

Re: Registering - number of visitors

dagger007 wrote:

do i maintain a visitors field in profiles table and update it every time a user visits the profile or how else if any other way

I can't think of any better way to do it. Is there a reason you don't want to take this approach?

Railscasts - Free Ruby on Rails Screencasts

Re: Registering - number of visitors

consider the scenario where there are more then one database server - 2 for read/select only, and 1 for manipulation C.U.D (typically) - if we were to execute an update on a view_profile action (which is pretty much what the user is going to be doing) then almost half of the total the requests will also be executed on the CUD server as... was wondering how would other websites like flickr and youtube have done it...

radical vision fuels disruptive technologies

Re: Registering - number of visitors

dagger007 wrote:

consider the scenario where there are more then one database server - 2 for read/select only, and 1 for manipulation C.U.D (typically) - if we were to execute an update on a view_profile action (which is pretty much what the user is going to be doing) then almost half of the total the requests will also be executed on the CUD server as... was wondering how would other websites like flickr and youtube have done it...

Are you going to launch with 3 database servers?

And maybe your database/network architecture should be redefined if you're going with a more write-intensive approach such as the one mentioned. Really I can't think of another way to do it other than writing to a file which has all the same problems.

vinnie - rails forum admin

Re: Registering - number of visitors

Make a new table having user id as foreign key and no of visitor as the other key.

Re: Registering - number of visitors

yeah - looks like there is no way around it - now a basic question - which way do you think is better - having a Nr_of_VISITORS field in users table or have a separate table all together for this purpose.

Plus can we "render" a different view then the action name - for example if i have a model called post, which has different types, each type requires a set of extra attributes then common ones - now i have one action "new" - but within "new" i determine which type of post it is and respectively render the view - e.g. new_job_post, new_enquiry_post etc

Plus can any one tell me how to render a view from within an action and store the output in a variable ???

plus can any one tell me how to disable the layout of the view from an action???

is there a guide/tutorial which could help maintain the line between presentation and business logics (keep them separate some rule of thumbs etc)

thanking in anticipation

radical vision fuels disruptive technologies

Re: Registering - number of visitors

dagger007 wrote:

which way do you think is better - having a Nr_of_VISITORS field in users table or have a separate table all together for this purpose.

Depends what information you need. If you just want the view count, a simple column should be good enough. If you want to see exactly who viewed the profile, when, etc. a separate table would be better.

dagger007 wrote:

Plus can we "render" a different view then the action name - for example if i have a model called post, which has different types, each type requires a set of extra attributes then common ones - now i have one action "new" - but within "new" i determine which type of post it is and respectively render the view - e.g. new_job_post, new_enquiry_post etc

def new
  render :action => 'new_job_post'
end

dagger007 wrote:

Plus can any one tell me how to render a view from within an action and store the output in a variable ???

Look into render_to_string


dagger007 wrote:

plus can any one tell me how to disable the layout of the view from an action???

def new
  render :layout => false
end

dagger007 wrote:

is there a guide/tutorial which could help maintain the line between presentation and business logics (keep them separate some rule of thumbs etc)

Not that I know of. I mentioned this a little in my tutorial. There's probably better articles out there somewhere though.

Railscasts - Free Ruby on Rails Screencasts

Re: Registering - number of visitors

thanks alot...

radical vision fuels disruptive technologies

Re: Registering - number of visitors

is there a variable called "back" - to redirect the request back to the page generating the action from within the controller ? e.g. render back ?? i saw this somewhere can't find it now...

radical vision fuels disruptive technologies

Re: Registering - number of visitors

Yeah. It's not a variable though.

redirect_to :back

Railscasts - Free Ruby on Rails Screencasts