Thursday, December 15, 2011

Adding Profile Fields in Diaspora


I have a friend/client that is using a customized version of Diaspora to host a community and allow them to engage with each other. We have made some changes, in order to better serve our community. I'm not a Ruby developer, myself. Some of this stuff may be obvious to those of us who are. However, for the rest of us, I put together this little guide to demonstrate how to do these things on your own. 

Adding/subtracting fields from profiles. 
We wanted to add the fields: "company," "twitter ID," and "company URL." I found you can do so by following these steps



STEP 1: Add columns to profiles table in MySQL. 
    I'm going to assume that whomever's reading this doesn't know crap about mysql either (well, you have to be able to login, and get to a mysql prompt).        Give your new field an alias. I went with company_name, twitter_url, and company_url. Once you're logged in to mysql, you're going to want to point to the DB (either diaspora_development, or diaspora_production). The command is "use diaspora_development".     


Screen shot 2011-12-15 at 7.45.49 PM


  Then get information about the profiles table, using the command "DESCRIBE profiles"  (this is so you can see what's going on with the table in general, not a necessary step).       


Screen shot 2011-12-15 at 7.46.34 PM


You can then add your columns, by using the command


"ALTER TABLE `profiles` ADD `new_column` VARCHAR( 255 ) NOT NULL;"       


Screen shot 2011-12-15 at 8.26.37 PM


PLEASE NOTE: I am 100% sure there is a way to do this by altering the schema.rb file, however, I wasn't able to make that happen by just editing and re-migrating so this was easier for me. If you could instruct me on how to do that I will replace this section.         


 


STEP 2: Open up apps/models/profile.rb starting on line 17 you will see some XML Attributes being declared with like so "xml_attr :property" add yours to the bottom like so:
Screen shot 2011-12-15 at 8.28.12 PM

Add them yet again on line 42:


Screen shot 2011-12-15 at 11.59.57 PM

STEP 3: 
///NOTE REVIEWER: DON'T KNOW IF THIS IS NECC. OR WHAT IT DOES, THOUGHTS?
On line 82 of the same file, you will see a function called from_omniauth_hash, add your new fields to the columns like so:
Screen shot 2011-12-15 at 8.36.11 PM


STEP 4:
   Now you need to go into the language files and add your fields. Open config/locales/diaspora/en.yml (or, whatever language version you are using) and starting at line 616 you will see the aliases for the different profile fields, add yours like so:      


Screen shot 2011-12-15 at 8.47.36 PM


STEP 5:        Finally, you need to update your view. Go to app/views/profiles/_edit.haml add the new h4 with your fields in it. Now you are done!


Screen shot 2011-12-15 at 8.55.27 PM



1 comment:

  1. Hello,very nice your blog, I search your blog from google and I know you know well of programming, and recently In want to find a programmer to review our product, of course, if the review is valuable, you will benifit.if you are interested in waht I said please e-mail me: michellechang524@gmail.com

    ReplyDelete