Topic: Storing 'visible' columns for a model

Hey,

I have a model measurements, with fields A,B,C,...
Now the user can generate a statistic image for this model.
But, the user can select which columns he wants to display in the image,
and this should be stored.

So I have to store something like true/false (visible) for each column.
How can I do this in an efficient way?

A table with fields user_id and column_name looks bad, since I have to compare
the column names when reading ..

Any suggestions?

Re: Storing 'visible' columns for a model

Christoph wrote:

A table with fields user_id and column_name looks bad, since I have to compare
the column names when reading ..

Can you explain this a little more? To me this solution doesn't seem too bad.

Also, have you considered placing this information in the session?

Railscasts - Free Ruby on Rails Screencasts

Re: Storing 'visible' columns for a model

it should be saved, because the image gets updated everytime the user adds a measurement instance.

I found this which might help:
http://api.rubyonrails.org/classes/Acti … ml#M001061

but somehow this seems a bit messy to me .. looping around and comparing the column names..
but I guess this is the only way

Re: Storing 'visible' columns for a model

You could just do this:

<% for visible_column in @visible_columns %>
  <%= @image[visible_column.name] %>
<% end %>

That is, assuming there is a VisibleColumn model which has a name column.

Railscasts - Free Ruby on Rails Screencasts

Re: Storing 'visible' columns for a model

the problem I meant is retrieving and saving the columns.
I'm not really sure how to do this, when using checkboxes for example.

But I guess I just have to create an array with the names, and save it as
the collection, then simply retrieve it and use include? to set the checkboxes to tru/false..

Re: Storing 'visible' columns for a model

Still not sure if this is what you're looking for, but you could loop through the column_names array for a given model to generate the checkboxes. You could loop through the same array to save the checkbox values again in the controller.

Railscasts - Free Ruby on Rails Screencasts

Re: Storing 'visible' columns for a model

yeah, thats what I did now... I guess thats the common way..

thanks ryan