Rails 3 best way to create a comment system for posts - ruby-on-rails

my first entry here.
I'm trying to add a comment system to our Posts model. However, I am not sure of the best way to go about it for a number of reasons. I'd like the comment system to be similar to that on Forrst.com but i'd rather have visitors who comment not need an account as the site is our company site not a large community.
Outline of features are:
Visitor can comment on post, entering name, email and comment.
Our team members can comment, i'd like these to be styled differently so would like the system to know it was from one of our team, they will be logged into the system when leaving a comment.
Visitors and team members can reply to a comment. The system needs to know which comment it was in reply to.
Lastly i'd like the system to know if the comment was written by the post author.
I have looked and been trying out acts_as_commentable_with_threading which seems perfect except everyone needs a user account to leave a comment, something I am trying to avoid unless anyone has other thoughts on that?
I have also implemented this myself by creating a comments model and using awesome_nested_set for the threading. Within the comments model I have a user_id which is only populated if the user is logged in (meaning they must be a team member), this seems a little messy though.
Does anyone have any thoughts on this?
Oh, and I would love each person to be notified of a reply to their comment (if pos).
Thanks in advance.

There are lot of tools available to post comments and working with ruby on rails.
http://ruby-toolbox.com/categories/rails_comments.html
also you can customize according your own requirement instead of writing a messy code.

If you do not want to integrate a third-party service like Disqus, you have Juvia The Comments and Commontator. Also you can count with opinio as alternative. but only with Rails 3 and at the moment and as notice the development seems stalled.

Related

rails survey - tracking when already answer

I've just implemented a simple model in my app, to create a survey. Simple question and some answer.
There is no need to be connected to answer the survey, but I want people to answer it just one time. How can I do that?
I don't know how to track this easily: IP, user agent etc. But these things can be easily changed. Any idea?

Rails routing, deep nesting for external resources

I understand that it's a good practice to only include in the URL the parameters needed to determine the object of the model.
If I have 2 models, Post and Comment... a Post has many comments and a comment belongs to one post. A URL for a comment can be
/comment/:comment_id
and from associations I can determine which Post it belongs to but
Some rails apps need to access external resources(Via APIs for example). If the rails app needs to replicate a part of another external source, what is the right way to handle URLs and routing?
If for example a post has some comments, The URL for a comment can be
/post/:post_id/comment/:comment_id
or
/comment/:comment_id
The latter has one disadvantage which is that I can't determine which post it belongs to if the API of the external source doesn't determine that and this would cause some problems with navigation through the app but it's a short URL and allows the user to easily manipulate the URL to get another comment(which I see as an advantage). At the same time using the first(long) link would make the URL so long but I can know which post it belongs to.
The only solution I can think of is to make both possible but the user would never know that the short one exists if I make the long one the default. What do you think?
I always use the longer / spelled-out version myself. I don't mind that it's long and I can only see good things come from it as you're discovering here. I also think it's an advantage because then you can do things like this:
post = Post.find_by_id(params[:post_id])
comment = post.comments.find_by_id(params[:id])
The point being that you can't go "comment fishing" this way. You have to have the right post context in order to get at a specific comment. This may not matter a whole lot if comments aren't at all sensitive, but there are many thing in a web app that may be. So scoping finds by a root object (like post here) allows a quick permissions check that can be reused and without having to check on parent objects.
Anyway, that's my 2 cents. I never understood why people take offense to the longer urls. If they work for you then don't be afraid to use them!

Ruby on Rails shopping cart: download and print options

I am building an online poster maker store with Ruby on Rails that gives the customer the option to either download a digital file for a generated poster or to have us print it for them and ship it to them. I am having troubles deciding where in my application to put this functionality. I am using a basic products, line_item, and cart structure.
Do I:
1) Make an option on the checkout that creates an Order if they decide to have us print the poster. If they just want the digital file it would just give them access on their user page after checkout.
2) Make a attribute on my line_item model that saves weather they want to download or print the file.
3) Something else entirely?
Thanks in advance for your help!
I believe I have found a solution! After talking to another developer friend, it hit me that the best solution might be to put all of the attributes for both printed and downloadable posters in the same products model and then expose only the information needed for each particular order.
For example,
If the order is to be printed by us, the user will be asked to fill out a shipping address form and asked what paper they want us to use. If they customer is just going to download the generated poster design these fields in the form will be hidden.
I believe that this is a much simpler solution then the two that I described above and will be the easiest to implement.

Rails application structure, advice?

I am about to start working on my second ever Rails application and could do with some advice. It will probably help in my head typing this question anyway!
The application's purpose is to track and monitor marketing campaigns. That makes it sound way more professional that what it actually is though.
An example usage:
Add list of possible client leads to application
Create a new "campaign" in the application
Choose who on the list of possible client leads should receive the
campaign
If and when a response is received it should then be possible to go into
that client lead's profile and mark
as "Positive Response" or "Negative
Response" etc..
Once the campaign is completed it should be marked as complete, I should be able to view in a campaigns profile who was a recipient of it and likewise if I view a client lead's profile I should be able to see which campaigns were sent to them and when.
That's the general idea of the application. I have made the framework and pushed it to GitHub:
http://github.com/dannyweb/Marketing-Manager
I am trying to get an idea of what models I would need, what sort of associations they should have etc.
I am unsure whether to use something such as acts_as_taggable and give each client lead a tag which relates to a campaign name?
If anyone can offer their thoughts or ideas on how this should be structured it would be greatly appreciated.
As it's my second Rails application - I am still very much a beginner, so please be kind! The application will remain open source on GitHub if anyone is reading this and would like to use the application.
Thanks,
Danny
I think you shouldn't turn to plugins (like acts_as_taggable) just yet. I'm going to give you some pointers but not much, because figuring out what works or doesn't is exactly what will help you learn more about rails.
So, you will have a 'Client' model and a 'Campaign' model. They have an N->N relationship (A campaign can involve multiple clients, and a client can be a part of multiple campaigns).
Therefore, you'll also need another table, which will have the 'client_id' and the 'campaign_id'. You also want to store on this table wether the client replied to it, so it'll need a 'replied' boolean flag on it as well. If you call this table 'campaign_messages', then client will need to link to campaigns using 'has_many :campaigns, :through => :campaign_messages'.
With these in place, you'll be able to list all clients on a campaign or all campaigns of a client easily. You'll also probably not need REST resource for the campaign_messages, only clients and campaigns.
That's all the detail I'm going to provide you. I think it'd be better if you just followed your approach now and asked how it could be improved instead.
Cheers and good luck

Handling user abuse in rails

I've been working on a web app that could be prone to user abuse, especially spam comments/accounts. I know that RECAPTCHA will take care of bots as far as fake users are concerned, but it won't do anything for those users who create an account and somehow put their spam comments on autopilot (like I've seen on twitter countless times).
The solution that I've thought up is to enable any user to flag another user and then have a list of flagged users (boolean attribute) come up on a users index action only accessible by the admin. Then the users that have been flagged can become candidates for banning(another boolean attribute) or unflagging. Banned users will still be able to access the site but will have greatly reduced privileges. For certain reasons, I don't want to delete users entirely.
However, when I thought of it, I realized that going through a list of flagged users to decide which ones should be banned or unflagged could be potentially very time consuming for an admin. Short of hiring someone to do the unflagging/banning of users, is there a more automated and elegant way to go about this?
I would create a table named abuses, containing both the reported user and the one that filed the report. Instead of the flagged boolean field, I suggest having a counter cache column such as "abuse_count". When this column reaches a predefined value, you could automatically "ban" the users.
Before "Web 2.0", web sites were moderated by administrators. Now, the goal is to get communities to moderate themselves. StackOverflow itself is a fantastic case study. The reputation system enables users to take on more "administrative" tasks as they prove themselves trustworthy. If you're allowing users to flag each other, you're already on this path. As for the details of the system (who can flag, unflag, and ban), I'd say you should look at various successful online communities (like StackOverflow) to see how they work, and how successful they are. In the end it will probably take some trial and error, since all communities differ.
If you want to write some code, you might create a script that looks for usage patterns typical of spammers (eg, same comment posted on multiple pages), though I think the goal should be to grow a community that does this for you. This may be more about planning than programming.
Some sophisticated spammers are happy to spend their time breaking your captcha if they feel that the reward is high enough. You should also consider looking at a spam server such as akismet for which there's a great rails plugin (https://github.com/joshfrench/rakismet).
There are other alternatives such as defensio (https://github.com/thewebfellas/defensio-ruby) as well as a gem that I found once which worked pretty well at detecting common blog spam, but I can't for the life of me find it any more.

Resources