views:

187

answers:

1

Hello, I have a problem with prepare data for JqGrid. I have used this plugin http://www.2dconcept.com/jquery-grid-rails-plugin and I need table with data from more models.

for example User model:

has_one :profile
has_many :users_roles
has_many :roles, :through=>:users_roles

and i need this data in jqGrid

[user.login, user.profile.email, user.roles.collect{|r| r.name}] 

Thanks for your answers.

A: 

Hi Suborx,

Just to be sure: The User <-> Roles relationship is a has_and_belongs_to_many, right? Because it looks like your avoiding the habtm by having "user_role"s and "roles through user_roles" specified.

I will work on displaying a habtm in a subgrid with exactly the plugin you use next week and post my solution here (if I find one).

val_to_many
Hi, yes it is N:N relationship and it could be habtm.
Suborx
Hi, so, I tried, but I didn't find a way to make this work. I tried putting the roles table in a row of the users table with a bitmap. (Railscasts 189).I buy into the fact, that the roles table does not make a lot of sense if you have to dig into the code to reflect changes in permissions. Anyway, I didn't succeed in finding a logic to build the jqgrid table that way by looping through each role and setting the variables to build the view... I actually go back to hierarchical roles in a one_to_many rel. and put them in a constant in my user model. I am sorry that I couldn't help!
val_to_many
thats ok... thank you for your time. :)
Suborx