I want to create a multi-domain app with Rails and have been wondering about the best approach.
The app will have a set of functionality that will be the same functionality across all domains, so the change in domain will only mean a change in the db used and the styling (and content obviously) but the models and controller will be the same.
The app will use MongoDB as the main storage (Redis for workers and other stuff that not directly relevant to model storage)
My idea is: Once a user signs up, a new record will be created but also a database will be created with the user id. The user model will store the database id (recently created), and the domain the user have just added. A vhost file would be created and the server reloaded.
Once the user visits the app (using the new domain). the app would check the url and find the correct db to use based on url. This would be saved into variable to be used throughout the app.
I imagine have this check to happen on each request.
I would appreciate thoughts and comments on this approach and best way to achieve this.
Related
I have rails app witch collect mobile data and use elastic search as search engine in my app, As result that my app is very simple I use elastic as my db, every things goes fine till I found something amazing
In my case each user have two kind of document with different attributes, First one is profile that it's about user profile only and Second one is events that is user actions in mobile app. I have to say، user could update his/her profile and each user just have to one document in my system, that is about profile details. each time user update his profile I delete previous document and create new document for him but assume he send profile twice at same time unconsciously for example push register bottom twice at this point i get two document that are completely same so elastic save both but as i say i need to delete old one and create new one, I know I could handle this problem in mobile layer but I'm looking for some way witch make me sure at this situation document have their priorities.
Basically you need a versioning of your documents and using that you can control whether you need to create a new document or update existing document. this official Elasticsearch version control blog should help you design and implement this use-case.
I really hope I got your point correctly, consider the following points
prevent users from submitting twice in your front end.
update the document instead of deleting the previous one then creates a new document so that you don't have to worry about document priorities because of a single file.
I have an MVC 5 application set up with windows authentication and my own custom roles table for authorization. This works fine if the user exists in my application database - username in my users table maps to the usernames in active directory.
My question is how do I keep my users table in sync with active directory. Any time a new user is hired, a new record has to be added to my intranet application to ensure this user has access to it.
Is there a way to load users from active directory into my own users table perhaps with some kind of scheduled job or is there a better way to achieve what I'm trying to do?
I think sync two database instances (AD database and you app database) will become management issue as your business grow. Even, adding new user and removing is day to day work, so in both cases you need to execute some sort of action to add or remove users from your app database.
Why don't you ask your team to give you access of AD database and consume this into your intranet app, this is what I was using in my past organization and this works great.
The AD can be used in a programmatic manner. Just look for LDAP stuff and you'll find lots of examples. Here's one to get you started : Connect to Active Directory via LDAP
If your application allows people to register then implement your own custom membership provider which talks to the AD. You can create the users in the AD, you will have to pass the password requirements which are set on the AD as well, which is more than likely a good thing. The roles information can be stored there as well, no need for a local custom roles table either.
Here I want to develop online chat application in Rails but without database so, I thought of using sessions instead.
Coming to application users will come to home page and click join chat button after that by filling two fields (like Name and Gender) his record should create in session.
after chat by closing his record should automatically destroy.
Is there any sample work-arround or example for this kind of application online?
This answer: https://stackoverflow.com/a/821269/382982 will help you remove Rails' default database dependency. Sessions should still work normally (http://guides.rubyonrails.org/action_controller_overview.html#session).
My Scenario:
Sessions are being stored in the database using ActiveRecord::SessionStore
User is on site at 'http://domain.com '
they go to secure checkout at 'https://domain.secure.com' (our app has lots of domains, but want to send everyone through secure checkout on the same domain to save SSL headaches).
We append session_id and a hash to authenticate and identify the user at 'https://domain.secure.com'
Load that users session data by doing ActiveRecord::SessionStore::Session.find_by_session_id(session_id)
The above all works fine. BUT how can I actually set the same session_id to the user once they are on 'https://domain.secure.com'? I can loop through the data and assign it to the user's session, but Rails automatically gives the user a new session_id on 'https://domain.secure.com'. I want the users session to be stored in the same database row regardless of whether they are on 'http://domain.com' or 'https://domain.secure.com'
Why do I want to do this? For ease of expiring sessions. I can just remove that row from the sessions table.
Otherwise I'm thinking I'll have to add a user_id column to the sessions table and then when i want to expire the session, I delete all rows for that user. But this sounds more complicated to me. I'd rather just have one row in the sessions table.
Any suggestions?
A couple ways to approach this.
One, you could look at a higher level of abstraction for authentication that lets you manage cross server. For example, Devise http://github.com/plataformatec/devise
Second, you can override the whole session controller and write your own session manager. A bit more work, but not that complicated if you ultimately need a bunch of custom functionality. I remember correctly, start with this in your environment:
CGI::Session::ActiveRecordStore.session_class = MySessionClass
and go from there..
What want to be accomplished is:
I want to "synchronize web browsers". my site has a "wait URL" where when browser gets there it will be kept waiting till another browser also go there and then both will be presented with a quiz-like game.
Right now the wait url will call each second to Rails to check if other player came to the game. How can in the Rails framework detect a different client connecting to the same URL?
As the controller is recreated per request looks like is not the place, not the view for sure and storing this in the model looks really clumsy.
Also, after the pairing I need to check and compare every answer of the paired users so somehow that information must be retained
What you're trying to do is share information between users. So the database or memcached are the most sensible.
Simplest: I'd create an ActiveRecord object, perhaps called Quiz, instances of which people join by virtue of going to a URL, e.g using default routes:
http://yoursite.com/quizes/join/3434
You'd need an ajax poller poller to notify the others; use periodically_call_remote for this -- you could use render :nothing => true by default and render something else if there was an error to keep it efficient. You can also use the frequency method as a basis to determine whether people leave the quiz as well (e.g. if frequency is 1s, then assume someone has left if they didn't ping after 5-10s).
Assuming these users are not registered with the site so don't have some kind of user id you could store I would suggest using the session. It is a per user data store. By default the session is stored in an encrypted cookie on the users machine. However you can use ActiveRecord as the session store and could maybe query that table directly?
Store the URL in the session and do a search for it at a later time. You can normally only access the current users session using the Rails 'session' hash but maybe (untested) if you created a model called Session (or maybe something more specific like 'WaitingGamers') which used the sessions table you could lookup the information you need.
I would guess when using ActiveRecord as the session store the session data is stored as a serialised hash. Use Marshall to turn it back in to a regular hash and find the data you stored in there.
I'm not a rails expert, but since all the state resides in your database that would be the place to keep this information.
You could keep a "waiting users" table, and in the "wait URL" view check if the user is already in the table. If not, add him to the table. Then, check if there is another user waiting (maybe there's more than one?) and if so, match them up and delete them from the table.
Another improvement would be to keep a timestamp for each user in the "waiting users" table, which gets updated in the view - this would serve as a keep-alive that will enable you to detect users that left the "wait URL" page or closed the browser.