Thanks Colin,
Thanks for the precise useful pointers, i will let you know the
outcome.

Cheers,
Sachin


On Apr 6, 9:07 pm, Colin Law <[email protected]> wrote:
> On 6 April 2011 16:36, Sachin Joshi <[email protected]> wrote:
>
> > Hi Colin,
> > Thanks for the pointers, in the mean time i got a work around on the
> > lines you mentioned.
> > Since it is HABTM relationship it is fetching array of accounts.
> > e.g.
>
> > def index
> >    @user = User.find(current_user)
>
> Is current_user a User object?  If so just do @user = current_user
>
> >    @account = current_user.account
>
> If you know (at the moment) that there is only one account then do
> @account = current_user.account.first
> If you are allowing for multiple accounts then call it @accounts not
> @account so that you will remember there may be several, or at least
> for the moment it is an array of 1 element
>
> >    @account.each do |a|
> >      @ac_id = a.id
>
> Why do you need the id?  Sometimes you do need to access the id
> directly, but mostly it is not necessary.
> Also remember that if the user has not got an account then
> current_user.accounts will be an empty array so in your code above
> @ac_id would not be assigned.  You may have to allow for this in the
> view (or wherever you try to use @ac_id).
>
> By the way could you not top post please, it makes it difficult to
> follow the thread.  Insert you reply at appropriate points in the
> previous message.  Thanks.
>
> Colin
>
>
>
>
>
>
>
> >    end
> > end
>
> > And i am able to use the @ac_id, but i am sure this not the clever way
> > to do this.
> > In the current specs i have 1 admin_user for 1 one account and this
> > account can have multiple users.
>
> > but this HABTM provision is made for future in which any of the sub
> > user of an existing account should be able to extend it to a owner
> > account.
> > I shall post any update..

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to