How to enable a Rails app to allow user customization of menu and other features? Including "app" installs - ruby-on-rails

I have a social network for gamers. It is in Rails 4 and uses PG. How can I add an "app" to it that changes the same site, and turns it into a site for movie enthusiasts, and most importantly lets users toggle back and forth?
gameexample.com would have a certain navbar. If you wanted, you could also "install" the movieexample app. movieexample app changes the navbar menu of the site, but keeps your other info, such as past messages, profile, interests, etc. Since many social networks share these basic things, why change? And changing "apps" would be seamless. You just click the button/icon. Some menu items are different, and your profile options and other people's profiles now emphasize different things (instead of gaming, now it's movies you want to watch, have seen, want to make, etc.)
You could access either site by it's own URL, but they would share the same DB. No having to sign up or in to a totally diff site. And the DB saves all your messaging, friends, etc across both sites.
I am using Rails 4.0.5 and PG 9.x. Also Bootstrap 3.
What is the most efficient way to have a site link so closely to another? Even if movieexample.com goes to movies.gamingexample.com, that's fine. But preferably not. More importantly though, how do I get the menu and everything to "scope" to each site? My best guess is to do
if [from movieexample.com]
then display [movie stuff]
else
[display gamingstuff]
Is that a reasonable way, or are there better ones? There is a link on each site back to the other.

Yes, you can use templates based on your domains, but it's too long to explain. Start using this guide:
http://www.justinball.com/2011/09/27/customizing-views-for-a-multi-tenant-application-using-ruby-on-rails-custom-resolvers/

Related

How do can I create web pages on the fly from an iOS app?

Context/Background: I have an iOS app with a Firebase backend. Each user on the app has a couple of public stories or journals. I am working on the v2 of the app and one of the main features of v2 is to give users the ability to publish their stories as static webpages by a click of a button. The goal is to have a journal for a user with a username "johnhouse", for example, be available at www.the-app-domain.com/johnhouse.
Question: How do can I create web pages on the fly from an iOS app? Im not sure where to start. Which online services should I look at?
I thought of spinning up a server and hosting www.the-app-domain.com on it, getting the app to ssh into the server and creating a directory called "johnhouse" (from the example above) inside the website's root directory and then pasting an index.html file inside it, But this doesn't only sound like a bad idea, it also sounds complicated as hell If I were to generate the html files on the app, how would I get them to the server? how would I get them into the right location?
There are a great many ways you might implement this behavior but I'll suggest one.
Consider what this product might look like if the app had no knowledge of how these static pages were published. All the app needs to be able to do is allow users to set which of their stories are published or not and to inform those users of the url at which their published stories will be available.
There may be real advantages to removing the app from your page-creation process.
If you find that you need to make change to the formatting of your pages you can do so without requiring an app update and you can choose if you want to rebuild every page or just have changes apply to new pages. This might be important if you discover that your pages don't render well on some devices or are not indexed the way you would like by search engines.
If you need to change where your pages are hosted you can do so (and provide redirects from the old location) without needing everyone to update to a new app version.
If you need to add moderation or curation of the content you publish you can do so more easily than if clients (your app) have direct control of your site content. This may be important when someone starts publishing SEO spam links to your site, or registers the username admin or login, or publishes a story containing malicious javascript, or publishes content which gets you a copyright infringement notice.
You don't need to give clients direct access to your web server which could allow them to edit each other's content or overwrite your site with their own malicious content.
Since you're already using Firebase take a look at how you might run your own web server as another client of this backend. One which looks for "published" stories (however you identify those in your data model) and generates appropriate pages for them. Depending on the tools you elect to use these could be dynamically generated pages (client side js or a web app) or static pages build by some backend process periodically or whenever stories change and added to a web server. Without any idea what server side tools would be most appropriate for you it's hard to know what specifically to suggest here.

How do I achieve single sign on and data sharing across 2 rails apps?

I am looking to set up 2 rails apps (with the same tld) which have single sign on and share some user data. If I have railsapp.com I will have the second app set up as otherapp.railsapp.com or railsapp.com/otherapp. I will most likely have railsapp.com handle registration/login etc (open to suggestion if this is not the best solution).
So lets say I sign up and upload an avatar and start accumulating user points on the main-app, I can then browse to the other-app and my profile there has the correct avatar and points total. is there an easy way to achieve this? Do the available SSO solutions create the user in the second app with the same user ID? if not, how are they tied together? (ie how can I query the other app for information I would like to be shared across the 2 - user points and avatar) I was initially looking at sharing a database or at least the user table between the 2 apps, but I can't help thinking there must be an easier solution?
I think the simplest solution is if you set the cookie on the .railsapp.com domain, then it should be sent when you do requests to otherapp.railsapp.com or any other subdomain (just stressing that as it might be a security concern). Remember to mark the cookie as secure!
And a extra bit you might need to make this work, is to store authentication tokens on a database so they can be shared between the two apps.
Disclaimer: I don't have much experience with Rails anymore, so I'm not sure if some of the frameworks like Devise can do something like this out of the box.
 Edit
Got curious and ... google had the answer: http://codetheory.in/rails-devise-omniauth-sso/

System Architecture : How to Use the same Banner ( like google banner ) in multiple different websites hosted in different domains or subdomains )

I have a new big project with ASP MVC 4 and I will need to build in the future a lots of tiny web application that contains:
A Banner ( like Google banner in black , for authentication, notifications , search …… etc. )
A body that must access the banner info and knows if the user is authenticated or not.
Let me explain, if we look at :
Google play (subdomain )
Google Map (subdomain )
Google Translate (subdomain )
Google Gmail (subdomain )
Youtube ( different domain )
We will notice that it’s exactly the same banner for all its subdomains and even different domain (youtube ), and they have just the content that changes, and if I’m already authenticated in google play I do not need to authenticate again in Gmail or YouTube .
I want to do the same thing with my websites :
here a link to explain in images: http://www.use.com/ba3e6c12424c7696be7f
My Questions or just need for confirmation:
1- It is possible to host a banner and websites in different domains and still not authenticate again in every websites? I ‘am thinking about YouTube domain and google domain which is possible. How can I get the same experience?
2 -I assume it’s very easy with subdomains without the need of OAuth 2 for authentication just the normal ASP MVC 4 simple membership will do the job, am ‘I right?
3- Assuming I choose ASP MVC 4 simple membership with subdomains , how can I organize my projects so I don’t have duplicated code for my banner in every project if i want the same experience as google banner ?
a) First idea is to build the banner, put it in an assembly and Render It with an HTML helper, is that a good option? )
b) Do I still have the same experience if I host every subdomain in a different server?
c) Can I choose to host the banner in subdomain1 and load It in a website in subdomain 2 with JavaScript? (do I still have the same experience)
4- Assuming I have to give every website in different domains (not subdomains), how can I manage the architecture? I just need some clues.
5- If I’m wrong on everything, can you guide me to have the exact same experience with complete different domains, or different subdomains with an elegant solution ?
Thank you in advance, and sorry for my bad English (third language).
You really have two separate questions here. First, how to include a bit of HTML in multiple projects. There's really a myriad of possibilities here. If all of your sites are in the same solution in Visual Studio, the easiest method is to simply pick one project to hold the partial view for the banner and then link to it in your other projects. You do this by right-clicking somewhere in your project in the Solution Explorer and choosing Add -> Existing Item..., find the file in the other solution, but instead of "Add" to confirm, click the arrow next to it, to expand the dropdown and choose "Add As Link".
Alternately, or if one or more of your sites is not in the same solution or is in another language altogether, then your best bet is probably just to save the snippet of HTML as a flat file, somewhere each site will have access to. Then, you just read in from this file and display it.
Your second question is more complicated: how to share authentication. If all of the sites are on the same domain (subdomains), then you can just simply set the cookie on the domain itself, and all subdomains will receive the cookie and have access to the authentication status. If you have sites on different domains, though, it gets exponentially more complex. You either have to implement something like OAuth, which is awkward if all the sites belong together (i.e. OAuth is only really used to authenticate with third-parties, no one really uses this to share auth between related but different domains.) Or, you basically create a server that provides authentication for the other sites.
It's a kind of complex setup, but you've seen it in action on places like Google-owned properties. When you go to login, it takes you to accounts.google.com, and then you're redirected to the originating site after logging in. Essentially, what's happening is that technically the only place you're "logged in" at is accounts.google.com. If one of the sites in the family needs authentication, it redirects you to accounts.google.com. At which point, if you have a auth cookie already, it's sent and accounts.google.com restores your authenticated session, it then redirects back to the original site, with some token that identifies that you are logged in. Going into all the details and how to actually set this up is far beyond the scope of what can reasonably be done here on StackOverflow, but this is a really good reference and starting point. Part 1 describes the theory. The next installment details how to set it up.

Integrating twitter,facebook and other services in one single site

I need to develop an application which should help me in getting all the status,messages from different servers like Twitter,facebook etc in my application and also when i post a message it should gets updated in all the services. I am using authlogic for authentication. Can anyone suggest me what gems/plug-ins i can use..
I need API help to get all the tweets/messages to be displayed in my application and also ways to post the messages to the corresponding services by posting it from my application. Can anyone help me from design point.
Walk through what you'd want to do in your head. Imagine the working site, imagine your webapp working before you start. So your user logs in (handled by authlogic) and sees a textbox called "What are you doing right now?". The user fills in a status message and clicks "post". The status message appears at the top of their previously posted messages.
Start with the easy part. Create a class that posts to two services. Use the twitter gem and rfacebook to post to two already defined services. In the future, you'll want to let the user associate services to their account and you would iterate through the associated services and post the message to each. Once you have this working, you can refactor or polish the UI a bit to round out this feature. I personally would do the "add a social media account to my profile" feature towards the end.
Harder is the reading of the data (strangely enough) because you're going to have to figure out how to store it. You could store nothing but I suspect you'd run into API limits just searching all the time (could design around this). I would keep a little cache of posts associated to the user's social media account. In this way, the data model would look like this:
A user has many social media accounts.
A social media account has many posts. (cache)
Of course, now you need to schedule the caching of the posts. This could be done manually, based on an event (like when they login) or time based. So when the update happens, you load up the posts for that social media account and the user will see the posts the next time they hit the page. For real-time push to the client's browser while they stare at the screen, use faye (non-trivial) and ajax to pull the new posts to the top of the social media stream view.
The time based one is tricky because you'd either have to have a cron job run or have rails handle it all with a gem like clockwork. But then you have to leave rails running. I've also solved this by having a class in /lib do all the work and a simple web call kicks off the update. But it wasn't in a multi-user use case. So that might not work. In any case, you'll want to have some nice reusable code for these problems since update requests can come from many different sources.
You'll also have to deal with the API limits. When pulling down content from twitter, you won't get everything. That will just have to be known by the user or you'll have to indicate a "break in time" somehow.
The UI should be pretty easy (functionally anyway), because you know which source the post/content is coming from. It'd be easy to throw a little icon next to the post to display which social media site it's coming from.
Anyway, good luck, sounds like a fun project.

Is it acceptable to make external links target="_blank"?

I'm a bit confused whether or not I should make the links on my website that point externally target="_blank". Does this practice negatively affect the usability of your site (i.e. breaking the "back button trail")? Is it commonly found annoying by most users? Is it acceptable in some situations but not others?
I want to make an enjoyable user experience for all of my sites and would hate to do something that annoys my users. What is your experience/advice on the matter?
Most people will say to leave it out, all for very good reasons.
Most people will not tell you this: watch how different people browse using their computer. Sit down for an hour with an average user: a teacher, a piano player, a retired Vet, a stay-at-home mother, or a mechanic. Watch how people who are disabled browse.
You will discover that you should not:
Open new windows (it is highly confusing)
Have menus disappear immediately after leaving them (requires fine motor control)
Use excessive numbers of links on a page (also confusing)
Provide too many features and options
Use Flash animation
Be overly clever
You will discover that you should:
Be clear and concise
Be simple
Keep the user on the same page
Avoid frustrating the end user at any cost
Create an extremely responsive website
And much more.
I've read plenty of usability documentation suggesting that end users resent being forced to open a link in a new window. I tend to agree, if I want a new window I will right click and select whether I want the same window, new tab, or new window.
However, the marketing types believe that opening an external link in a new window will keep the end user on your site because they will eventually close the new window and wind up back on your site.
EDIT: Best information I've read on this subject is in Steve Krug's book "Don't Make Me Think" (website).
MHO: just link it. If I want to open the link in a new window, I can do it myself.
Leave the target attribute out and let your users decide if they want to open the link in a new window. If you want to warn the user that the link will take them away from your site, you can implement a page that makes it clear (US Government sites do this for instance).
I agree that as a user, I prefer to have the choice as to whether or not I open a link in a new window. Unfortunately, many users don't realize that they have that choice, and will lose your website when they click a link to an external site. I tend to err on the side of caution and make external links open in new windows, but it depends on your audience, really.
Here is a nice write up for not opening links in a new window/tab from Smashing Magazine. Essentially, it is better to give users control over link behavior than to decide for them.
Usability guru (?) Jakob Nielsen suggests not opening new browser windows (It's 10 years old though).
Quote:
Opening up new browser windows is like
a vacuum cleaner sales person who
starts a visit by emptying an ash tray
on the customer's carpet. Don't
pollute my screen with any more
windows, thanks (particularly since
current operating systems have
miserable window management). If I
want a new window, I will open it
myself!
Designers open new browser windows on
the theory that it keeps users on
their site. But even disregarding the
user-hostile message implied in taking
over the user's machine, the strategy
is self-defeating since it disables
the Back button which is the normal
way users return to previous sites.
Users often don't notice that a new
window has opened, especially if they
are using a small monitor where the
windows are maximized to fill up the
screen. So a user who tries to return
to the origin will be confused by a
grayed out Back button.
And, every rule has an exception: He suggests document like PDF or DOC that are opened in the browser should be opened in new windows, to avoid confusion.
It's worth mentioning that target isn't valid in XHTML anyway.
I think it depends on the situation. For a simple website with just a few links like about us, contact, services etc., I will not open new window. It is easy for the user to know which page they are at and which page they have just looked at. For a site that has a listing summary page which links to hundreds or even thousands individual listing page. I would prefer to open new window for each listing. It allows the users to compare service/price.... on each opened page. Plus the user doesn't have to click the "back" button to return to the summary page and wait for the same page to load again.
It depends, typically for links to additional content on your site, I would not use the _blank. Anytime I link to off-site content I use the _blank to keep a page open for my site. That way when the user is done on the external site they see my site again.
With modern browsers this usually opens a new tab. I expect this behavior, but usually I control click to get a new tab/window when I want to keep my place.
That being said, for a web application, I'd always leave the target attribute off so the user can decide to open a new window or not.
What people hate is opening links in a new window and not knowing that it's coming. For each external link, go ahead and use target="_blank", but add an icon that suggests you're opening a new window. Wikipedia's double square icon is a good example of this, so you can just grab that from them and capitalize on the literacy that users already have there.
What's great about a 'new window' icon is that users then have the option of opening in a new tab instead, which isn't so obtrusive. I'd also say that many of those vehemently arguing against your proposed approach are looking at it strictly from an aesthetic/usability standpoint, and not in terms of business requirements or the functionality of your own application.
If you think that you or your users stand to gain from keeping users on your site and opening external links in a new window, you get to make the final call on that. Just be respectful about it.
You need to consider what users are doing in your window, when deciding how links should behave. If I could potentially lose a lot of work by navigating to another page, then I might want links to open in new windows, or give me an option to cancel.
For example, if I'm composing a message in Gmail, most of the links show a confirmation dialog, so I don't accidentally lose my work. And the links on top, which go to other applications like Calendar, open in new windows. I think this is a good example to follow.

Resources