El Monday 12 January 2009 12:34:51 DJ escribió:
> Hi
> Sergio
> I could not understand why i need a select box for roles
> in roles controller? I simply need check boxes for roles in user's
> creation or updation . Also abt the roles, i have separate model by
> which i can create , update and delete roles.
> Now as user and roles maintains HABTM relationship so i should be able
> to fetch roles for each user for both create and update operation.
In your users controller you should have a roles column and you have to set
select form_ui for it.
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
has_and_belongs_to_many :users
end
class UsersControllers < ApplicationController
active_scaffold do |config|
config.columns[:roles].form_ui = :select
end
end
>
> And i indeed done one select interface in one of my controller like->
>
> module EmployeesHelper
> def user_column(record)
> if record.user.nil?
> ""
> else
> record.user.id
> end
> end
>
> def user_form_column(record,input_name)
> options = User.find(:all).collect do |c|
> [ c.email, c.id ]
> end
> select :record, :user_id, options, {:include_blank =>
> false, :prefix => input_name},
> {:name => input_name + '[id]'}
> end
>
> end
>
> and then config.columns[:user].form_ui = :select in userscontroller.
You don't need those helpers to use a select form_ui, it's builtin in active
scaffold, you only have to set form_ui to association column. Try setting
form_ui and removing user_form_column.
If you add a to_label method to user, it will be used to show users in select
and in list, so you can remove user_column helper too.
>
> I do hope , i am not missing anything
> Dwija
>
>
> On Jan 12, 3:27 pm, "Sergio Cambra .:: entreCables - Symbol Servicios
>
> Informáticos S.L. ::." <[email protected]> wrote:
> > El Monday 12 January 2009 11:19:22 DJ escribió:
> > > Hi
> > > Groups
> > > I am trying to show a group of check boxes along with
> > > their boolean values for a HABTM relationship say
> > >
> > > has_and_belongs_to_many :roles
> > > has_and_belongs_to_many :users
> > >
> > > so the roles table are ->
> > > id name type
> > > 1 create ..
> > > 2 read ..
> > > 3 update ..
> > >
> > > users tables->
> > > id name email
> > > 1 admin ...
> > > 2 harry ...
> > >
> > > roles_user table->
> > >
> > > role_id user_id
> > > 1 1
> > > 1 2
> > > 2 2
> > >
> > > What i am trying is to show the check boxes for every role name along
> > > with their boolean values(checked or not) in each users update form.
> > > I have tried with name_form_column in user helper function but could
> > > not get the desired result. Are their any better way?
> >
> > Have you tried to set :select to form_ui?
> > config.columns[:roles].form_ui = :select
> >
> > --
> > Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
> > Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
> > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>
>
--
Sergio Cambra .:: entreCables - Symbol Servicios Informáticos S.L. ::.
Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---