I'm new here and I thought I could ask a topic about creating a friend's list for users in my small rails project, since I couldn't find an answer specific enough to what I'm looking for.
I'm trying to make a basic friend request, so that I can have users in a database use a 'friend' function to keep track of players they like, so that they can keep in contact, etc. I currently am thinking that I need to use a has_many relation in regards to setting things up, but I'm not quite sure where to take it from there, besides just having each user have a list of names they wish to keep. If that's how it's done, how would I code that so each user has a list of users they wish to keep, as well as remove, add, email, etc?
It depends on how much complete and complex you want to implement it into your project.
You may want to use a gem, like amistad or has_friendship, which are plain simple to install and use. You also have socialization, which has a follow/mention/like usage like Twitter does.
If you want to learn how to code that from scratch (e.g. educational purposes), this railscast is pretty good at explaining how to implement that feature.
And if you want something even more complex, you have some gems that gives you features that you usually have at a social network (friends, photos, personal blogs and so on...): social_stream or diaspora
Related
I'm working on fairly standard Ruby on Rails app where users have many studies. When a user signs up, I would like them to have a sample study as an example, similar to how Trello gives you a sample board on sign up.
My current approach is to deep_clone Study.first on registration and assign ownership to the current user. This means new users can edit their clone of the sample study and no-one else can see their changes. This works fairly well however it has now become quite complicated to clone studies as my associations are a lot more complex.
To simplify, I would like to change my approach for the sample study. Instead of cloning, I now want to give everyone access to the first study in the database, but read-only. Studies have a few views, e.g. users can change questions, participants, settings, add tags, etc. They should be able to see existing questions, participants, settings, and tags, but not add, remove, or edit them for this sample study.
I believe I need to:
Figure out how to make Study.first show up for everyone in all the right views without it actually being owned by current_user
Make this study read-only for everyone except me
What's a good approach for doing this in Rails?
For a classical server side application there are few ways around that you would need to use some sort of persistence to store the users changes between requests.
You could possibly setup some sort of inheritance so that studies can inherit from another study and use delegation to avoid duplication.
class Study
belongs_to :master, class: 'Study', optional: true
def get_some_field
master ? master.get_some_field : super
end
end
If the user is manipulating questions, participants, settings, and tags they should merely be working on join tables which are pretty cheap since they only involve storing two integers per row.
Another solution could be storing diffs or just the actual changes the user performs. It might be possible to use paper_trail or at least study it as a starting point.
For an ajax heavy application or SPA you might want to use local storage to fake the whole server interaction.
When a user creates a demo study they would fetch /studies/1.json and then when the play around they are just manipulating the object stored on the client.
In Ember you could for example swap out the adapter to ember-localstorage-adapter.
I'm still learning rails but want to be sure I'm heading in the right direction. For several of my models I want to let a list of users know that updates have been made when a new record is created for example. I'd like to tie this to an email and in-app notification(doesn't need to be AJAX), next page refresh is fine.
I've been reading up on observers some and I think that's what I want but they seem somewhat controversial based on the blogs I've read. Services like Pusher seem to be overkill for my needs.
Would this be a good solution for this scenario? Also, can anyone point me to some example code that I could emulate?
Thanks!
Check out Rails Cast if you are trying to learn. Best free code base I have seen. Also check out this book another great learning tool. Agile Web Development with Rails (2nd edition).There might be some newer ones out but I have not checked.
I am considering implementing a Facebook-integration to my web app. I want to be able to import friends names, their ages and their interests/likes.
A. First off, is this possible? Can I access this information?
This import will, more or less, be a one-time import.
I also want to be able to use Facebook-login and to use it parallell to my "normal" login (auth) functionality. I assume this should be quite straightforward since most websites have it this way (e.g. Fiverr.com).
B. These two things being my basic needs of my Facebook-integration, which gem would you recommend me to use?
C. I am 1 1/2 years into RoR and consider myself decent at Rails-programming but hardly know any JavaScript and very little jQuery. Will this integration be very difficult for me, you think?
Receommendations of useful blog posts etc will also be appreciated!
A. Check facebook doc on permissions. I'd say you can get a user friends list (id and names), but nothing more : the friends would have to allow your app in order for you to retrieve their data. I've stumbled upon this issue a few weeks ago, but we were retrieving albums and pictures. The data you want is less sensitive, so maybe you can do it anyway. Bottom line : check.
B. I'd suggest using devise for managing everything related to authentication. It is a well known gem, used by many and more. You can add support for facebook via omniauth; there's a wiki page on devise about how to achieve this.
C. Once you get your grasp around the OAuth concepts, you'll be good. You can use facebook connect without javascript/jQuery. Some features though, as the "like button", will require to use the js SDK. Besides these ones, you can do pretty much everything server-side. For more advanced queries, the koala gem can do that.
Hope this is enough for you.
I've been thinking of writing my own backend, because I feel active_admin might not support all the requirements.
I wanted to ask if Active_Admin supports any of these just to be sure:
I have a has_and_belongs_to_many relationship between my ad model
and tag model. In the new ad page I would like to have the form for
the ads, as well as all available tags so the admin can choose which
tags to associate with the ad. I was able to do that normally in my
application, but can I do that with active_admin?
Can I add custom buttons.. Like one to convert to PDF for example,
or one to send an e-mail..
Could I add some sort of before_filter, so the admin can only view a
model, but not edit or delete it for example?
Thank you.
All of those things can be done via Active Admin, but as it was pointed out, it can be quite a nightmare actually implementing certain things depending on the amount of flexibility you need it to have. For that exact reason, I decided to start rolling my own administration panels.
I have tried an implemented almost all robust gems for admin panels. I have also sweated over several hand-made ones.
Active-Admin is very usability centred, but it is not configuration centred.
As you rightly aniticipated, some of the more complex modifications can be tedious.
In my experience, rails_admin is the best middle ground I could find.
Take a look at it, it is highly functional, completely modular (made as a Rails 3 Engine) and simpler to modify.
If you can live without some details when customizing this is definitely the way to go. However, if you need to have everything just right, then there is not substitute for hand-made.
I have a rails app in which I am trying to do some full text searching on. Ferret seems to be the most popular choice. However, I have an issue.
I have a 'thing' which contains an id which determines if a user can see it (and therefore search it), but I want to search sub-models of this 'thing' which are related to my 'thing' but don't directly contain any references back to the user.
Therefore, how do I implement it? Is there a clever way of implementing this, or do I need to dirty my models with a link to the domain identifier?
I think it would be very wrong to assume that Ferret is the most popular choice for this. Most people I know have ditched Ferret and replaced it with Sphinx. And the people who can't use Sphinx for some reason have opted for Xapian.
That said, the answer to your question is likely to be largely the same regardless of the indexing system you choose:
When you're dealing with permissions and indexing, you can't effectively index anything related to the permissions system because it's going to be user-specific. All your permissions stuff needs to live in your models/controllers somewhere. I'm fond of putting all my permissions stuff in a module and then including it in my model, so that I can easily share it between models.
Pagination can be a real pain for this kind of thing because you request 10 items from your search engine, and then your permissions code rejects 5 of those items, which means you have to keep running searches until you have your first ten items to display. And now when you want page two, well, things turn into a real mess then. Heaven forbid they decide to skip straight to page ten, because now you can't do tricks like giving a start ID instead of a page number. Really, it's not something you want to do at all if you can help it.
There really are no "clever" ways of getting around the mismatch between permissions and full-text indexing. At least, none that I know of. It's just a pain.
I suggested to my boss when we first started out that the only sane solution was an egalitarian permissions system: If we gave you a username and password, then you have access. He wasn't a fan.