rails project help - ruby-on-rails

i am trying to get my head around the best way to develop an app in ruby on rails
i have a ducument creation system that for each document has multiple associations ie text docs, images, optional accessories etc. I have created this system now to do CRUD.
The next thing i want to do is have each document able to be translated into multiple languages and each document need to be versionized and audited with whats changed when and who dun it etc. Also i need to be able to clone a document for another user so he can then edit it for himself and with all above version and audit features.
I have looked at Globalize2, acts_as_audited, acts_as_versioned, paper_trail and deep_clone and sort of need abit of each !
Please can anyone help me with how or what is the best method of develping this app ? Is there better more suited plugins to use ? can these be used with each other ? and what would be the best process to set this up ?
any help would be most appreciated.
thanks
Rick

thanks askegg for your reply
the thing is acts_as_version does not include your models relations and i need to version each document model along with the children asscociated models ?
So basically if i dont use Globalize my transplated documents will just be other versions but in a different language. Is that correct ? I thought that is what Globalize does ?
thanks alot
rick

It seems you have a grasp of the basic structure you want and have investigated some alternatives.
First pass of my reading: You have a Document model, probably with a polymorphic association to an Asset model. Come to think of it, a Document is just a type of Asset, so one could inherit from the other - perhaps Single Table Inheritance.
From here, add acts_as_versioned to deal with ....well, versioning. This should also be able to give you the differences between various versions, just ensure you record the user_id along with the change.
I am not sure Globalise or i18n will help you here, as they are more geared to translating the web site itself with reasonably static content, not highly dynamic documents such as you're dealing with. I would leave translations to the users and use i18n to present different translations of the web site itself.
Cloning a document should not be too difficult - just create a new Document and populate the information in it. You will probably need a cloned_from_id field and build a self referential has_many in the model.
Well, they are the thoughts off the top of my head.

I was thinking you might treat each image, document, pdf, whatever as separate assets each with their own versions - operating independently of any other. If you need to clone a document and it's children, then you would need to iterate over the children and clone them as well - and their children's children. etc.
Globalise (or any other translation platform) is only really good for set/simple statements. Due to syntax and grammatical issues I would not expect it to be able achieve good translations between languages. Humans are great at that.
It occurs to me that you might want to think about using Git as a document store. This gives you full document versioning with tracking changes. See this presentation for some ideas. Don't worry about all the tech details - just think what it can do for you. The good stuff start about 15 minutes in. The Grit Ruby library can be found here.

Related

How to handle article revisions?

I'm creating a knowledge base web app in Ruby on Rails. I'm looking for various ideas on how to handle revisions of the same article.
At this point, I have a table called contents and versions. Versions belongs_to the Content table and has a foreign_key to content_ID. However, from this point on, I'm not sure how I'm going to implement saving to different versions, auto-save, and allow authors to recover from certain version and making a particular version as the current version. Any suggestions, opinions, and links are all appreciated.
Version control can be tricky but check out paper_trail: https://github.com/airblade/paper_trail

Un-bloating models in rails 3.1

Just learning rails, developing first app and having trouble finding a straight answer to this question!
I want to keep my models as lean as possible and really only want to use them to represent objects that I might want to render in my views. Therefore, I want to remove some of the logic from one particular model and store it in a separate file. I have seen numerous guides (on this site and others) that suggest the following;
never "require" anything from inside a rails app
Store additional files in the lib folder - they used to be auto loaded in older rails releases but now you need to add an extra line in a config file to get this to happen (Example.
So I added the line, stuck the file in the lib folder, and it all worked fine. So on to the question;
I can't shake the feeling that the fact that I had to go and put some bespoke code into the config file means I'm doing this wrong (given convention over configuration). Why are people having to faff around editing configuration files to get rails to do something so basic?
Is that the best way or are there additional considerations that I'm just not seeing? Should I in fact be creating an "extras" directory rather than still sticking things in lib?
If anyone can point me in the direction of a definitive article on the matter I'd be much obliged!
There is nothing wrong with having non active record models in the model folder. If your domain is best modeled by a business logic layer and a persistence layer, then model it that way in your model folder with appropriate naming conventions. Personally I wouldn't be overly concerned with getting it perfect. Try something and see how you like it.. learn from your mistakes and keep getting better! Above all, enjoy the process.
what I do is this: keep the model logic in the model and keep the controllers as thin as possible
If there are things that should belong to your model but are somewhat distant to it (for example you have an Account model and you're working on some payments system which relates to the Account - for example you might want to call account.has_subscription?, you could use a gem called concerned_with which would split your model's main actions from others like the ones handling payments (this is just an example I recently had to take care of).

Versioned associations using vestal_versions?

I'd like to be sure if vestal_versions does support versioned associations (it seems like it doesn't) before switching out to another versioning gem that can support versioned associations e.g => has_versioning. I haven't looked at the code yet but I couldn't find anything related with versioned associations from the readme file or the issue section on github. Help would be appreciated!
(At the moment of writing this) There is an associations branch in the official vestal_versions repository, It is still a basic idea and isn't merged yet in the master branch. So I decided to go with another versioning gem, specifically acts_as_revisable following the instructions in this blog post.
I'm looking for something that appears to be very close to your needs. But I don't need to revert the associated objects, just to record them. I was thinking of handle it in a nosql way. So I can save the model version and the associations would be embedded documents.
So I can compare versions in a more comprehensive way. Right now I use paper_trail, but as it can't handle associations, it's not possible to store the tags associated to a model and see how it changes through time.

Rails "Badge" type plugin / tutorial?

Does anyone know if there is a Rails gem/plugin/tutorial that shows how to create a Badge/Achievement system similar to what stackoverflow uses.
Thanks.
You might also want to try the achievements gem: https://github.com/mrb/achievements
It's based on Redis, so you'll need to get that working first. Basically, you define a bunch of achievement contexts (pages viewed, messages sent, etc.) along with multiple levels if necessary. Then, you increment your value appropriately upon certain events, and you can then check if the achievement has been reached.
This link also has a relatively detailed explanation of the thinking behind a badge/achievement system: RoR Achievement System - Polymorphic Association & Design Issues
check out https://github.com/paulca/paths_of_glory
I think it's less a framework but a design question. If you know how to build it in an object-oriented way, you'll eventually know how to build it in Rails too.
If you're a Rails newbie, check out the Rails Guide on "Active Record Associations" and try to identify the models and the associations of your "badge/achievment system".
Besides that: No, I don't know of any turnkey-gem/plugin/tutorial that would help you build such a system.
There is also Gioco, which I haven't yet tried:
http://joaomdmoura.github.io/gioco/

What's the best way to store the ActiveRecord Models with Versions and their Associations with Versions?

If all I have is one model (for example Wiki) and want to save it along with its versions, I could use acts_as_versioned plugin which stores the wikis in "wikis" table and its versions in "wikis_versions" table. This is plain an simple even if I want to moderate the latest version before showing it to the public using a field as status with "pending review/ published".
What's the best way to handle Wiki with associations (for example attachments, assets,..) which also have versions? And how would you moderate it? Do you create a new version to wiki even though only its association is changed just to keep the flow going, if so what about other associations?
What's the best way to handle it with little db overhead?
Thanks in advance.
I have used both acts_as_versioned and acts_as_audited.
I prefer the latter because it uses a single table. Using acts_as_versioned we've had issues with changes to versioned tables requiring extra migrations => this adds extra complexity to our build and deployment process.
Richard Livsey has a nice plugin for this that works with acts_as_versioned.
http://github.com/rlivsey/acts_as_versioned_association/tree/master

Resources