How to set parent id when using nested attributes form? - ruby-on-rails-3

I am building a Rails 3.2 webapp. In this app I am using the gem Act_as_tenant.
I also got accounts (tenants) that has many users (trough a join table).
I am creating both the account and the first user using nested attributes.
The user model got an attribute called account_id which I need to fill with the created account. Both the account and the user is created successfully BUT the id of the newly created account is not set in the users model (account_id). How can I make sure it is?

Related

How to create new portal user using web/signup url in odoo

Hello I want to create new portal users using web/signup url using backend. I want to create like this because I want to add tests in my module. My module assigns company id of users that created by using /web/signup page. I have multiple website. If user signup from website 1, it will assign company of website 1 in created users.
You can create a new user record by using create method from res.user model. For example,
self.env['res.user'].create({...})
You will need to pass an object containing required fields into the method for it to work though.

rails user authentication on mulit tenancy system

Im currently creating a multi tenancy system in rails 5 using the gem Apartment
I have a Tenant model which contains a Name and Tenant so I can create individual tenants (or companies).
Each tenant has a users table. When a user logs in I set a session containing the user_id. The problem is when I switch subdomains it then picks up the user id from the second tenant and shows me logged in as them.
for example: on tenantA im logged in a Brad (user_id:1 on tenantA user table)
when I switch to tenantB im logged in as Dave (user_id:1 on tenantB user table)
Obviously this is no good as you can access data from another tenant.
Im just not really sure how to restrict users access to only their tenant. I think maybe some sort of scope on the session so it only applies the session to the current subdomain and not all of them, but not sure how to do this.
Has anyone done this before that could help me? Not sure what code to paste here but just let me know and I will post my code.
Thanks in advance

Associate custom objects with a particular user

I am working on a Titanium Alloy project where in I am creating custom objects using ACS. I also have different users in the Users ACS. I wish to associate a particular custom object to a particular logged in user.
For example, If user A is logged in the custom object created by that user should be associated to user A. Same for user B and so on. How do I create this association? Currently my Custom objects get created but they are not associated to the logged in user.
After a little discussion, I realised I should add my scenario too.
My scenario is, a user changes a few settings using the toggle switch. This information should be stored for a user and later on push notification for selected settings should be sent to the user.
Any help in this regard is greatly appreciated.
Regards,
Shreerang
So i think you should store custom object in database with its user name so whenever you want you can get back with user's name.

How can a user update another user's tag?

I am designing an app where a user adds another user to a group. I am implementing groups with tags. So one user has to change another users tags.
From the documentation, I can deduce that only the user can update its own information. So how can I do this?
You're right - only user can update own tags.
You can do it using CustomObjects API http://quickblox.com/developers/Custom_Objects
For example - create Group entity and use it for this purpose.
CustomObjects API has Permissions API - http://quickblox.com/developers/Custom_Objects#Permissions
So you can set who can update your records

How to create a form in Rails that adds information to multiple tables in the database?

I'm working on an application where during the registration process users must enter information such as the following:
e-mail
password
company
package (the user would select a package from a list)
In my database, I have a table for users, companies, and packages (a separate table for each).
How do I make sure that the information from the "User Registration Form" goes to separate tables in the database? To be more specific, how does the single registration form (1) adds the user's e-mail and password to the "Users" table & (2) adds the company name to the "Companies" table?
You need to use accepts_nested_attributes_for :packages in your User model. Then you can use fields_for in your view to allow package info to be submitted from the user form.
If you need a more in depth example of how to use nested forms, have a google around. I believe railscasts has a good tutorial for it.