My table has a number of columns that are for record keeping, and I don''t want to display these column names back to the user when I display data. Is there a way to tell RoR to only display column names that I tell it to display? I''ve looked at the API, but the closest thing I saw was content_columns, which doesn''t filter out all the columns I don''t want to display. Is there a way to tell RoR to only list selected columns? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
then siimply don''t show them. in your view if you don''t want to display, for example, the description field, then don''t put <%thing.description -%> in your view. On 6/11/07, Daniel Legrand <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > My table has a number of columns that are for record keeping, and I > don''t want to display these column names back to the user when I display > data. Is there a way to tell RoR to only display column names that I > tell it to display? I''ve looked at the API, but the closest thing I saw > was content_columns, which doesn''t filter out all the columns I don''t > want to display. Is there a way to tell RoR to only list selected > columns? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I understand I could do that, but is there a way to do this already pre-built into RoR? This is a fairly common thing, and RoR should have this kind of capability. I was hoping there was a place where I could tell it to only display columns that I specifically tell him to, without having to hardcode each column name into my view. That''s not very dynamic, and kind of a drudge to do. Thanks for you advice though, Chris. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Legrand wrote:> I understand I could do that, but is there a way to do this already > pre-built into RoR? This is a fairly common thing, and RoR should have > this kind of capability. I was hoping there was a place where I could > tell it to only display columns that I specifically tell him to, without > having to hardcode each column name into my view. That''s not very > dynamic, and kind of a drudge to do. Thanks for you advice though, > Chris.Oh, you clearly don''t have to hardcode each column name into your view. If you are actually going to render all columns exactly the same way, then just loop through a list of columns that you pass to your view. Guest -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Guest wrote:> Daniel Legrand wrote: >> I understand I could do that, but is there a way to do this already >> pre-built into RoR? This is a fairly common thing, and RoR should have >> this kind of capability. I was hoping there was a place where I could >> tell it to only display columns that I specifically tell him to, without >> having to hardcode each column name into my view. That''s not very >> dynamic, and kind of a drudge to do. Thanks for you advice though, >> Chris. > > Oh, you clearly don''t have to hardcode each column name into your view. > > If you are actually going to render all columns exactly the same way, > then just loop through a list of columns that you pass to your view. > > GuestI know I can loop through them, but that''s the problem; there are certain fields I don''t want to display. If my table has these columns: name, email, created_at, and created_by, all 4 column names are displayed when I loop through the columns to display them. I only want to display the name and email columns, while excluding the created_at and created_by columns. Is there any way to do this or will I have to write my own? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Legrand wrote:> Guest wrote: > >> Daniel Legrand wrote: >> >>> I understand I could do that, but is there a way to do this already >>> pre-built into RoR? This is a fairly common thing, and RoR should have >>> this kind of capability. I was hoping there was a place where I could >>> tell it to only display columns that I specifically tell him to, without >>> having to hardcode each column name into my view. That''s not very >>> dynamic, and kind of a drudge to do. Thanks for you advice though, >>> Chris. >>> >> Oh, you clearly don''t have to hardcode each column name into your view. >> >> If you are actually going to render all columns exactly the same way, >> then just loop through a list of columns that you pass to your view. >> >> Guest >> > > I know I can loop through them, but that''s the problem; there are > certain fields I don''t want to display. If my table has these columns: > name, email, created_at, and created_by, all 4 column names are > displayed when I loop through the columns to display them. I only want > to display the name and email columns, while excluding the created_at > and created_by columns. Is there any way to do this or will I have to > write my own? > >Daniel, to avoid having to do that have a look at one of the automagic scaffolding generators/plugins: auto-admin/activescaffold/streamlined/toffee/hobo HTH Mike -- Mike Gilbert email : mike-jLbnyU+aYbUAvxtiuMwx3w@public.gmane.org Technical Director fax : +353 68 470 01 XL CRS mobile: +353 87 677 2055 Lisselton phone : +353 68 470 10 Listowel skype : kingdomdude Co. Kerry web : www.xlcrs.com --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel, I think you need to tell us how you are displaying your data. Rails by itself does not do any display by default unless you use scaffolding. if you are using scaffolding, it''s meant to be built upon (hence the name ''scaffolding'') and customized to your needs. Chris On 6/11/07, Daniel Legrand <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Guest wrote: > > Daniel Legrand wrote: > >> I understand I could do that, but is there a way to do this already > >> pre-built into RoR? This is a fairly common thing, and RoR should have > >> this kind of capability. I was hoping there was a place where I could > >> tell it to only display columns that I specifically tell him to, without > >> having to hardcode each column name into my view. That''s not very > >> dynamic, and kind of a drudge to do. Thanks for you advice though, > >> Chris. > > > > Oh, you clearly don''t have to hardcode each column name into your view. > > > > If you are actually going to render all columns exactly the same way, > > then just loop through a list of columns that you pass to your view. > > > > Guest > > I know I can loop through them, but that''s the problem; there are > certain fields I don''t want to display. If my table has these columns: > name, email, created_at, and created_by, all 4 column names are > displayed when I loop through the columns to display them. I only want > to display the name and email columns, while excluding the created_at > and created_by columns. Is there any way to do this or will I have to > write my own? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Hall wrote:> Daniel, > > I think you need to tell us how you are displaying your data. Rails > by itself does not do any display by default unless you use > scaffolding. if you are using scaffolding, it''s meant to be built > upon (hence the name ''scaffolding'') and customized to your needs. > > ChrisChris Hall wrote:> Daniel, > > I think you need to tell us how you are displaying your data. Rails > by itself does not do any display by default unless you use > scaffolding. if you are using scaffolding, it''s meant to be built > upon (hence the name ''scaffolding'') and customized to your needs. > > ChrisI have a "children" table that is assocated by "parent_id" to a "parents" table. I want to display the children, but I only want to display relevant information back to the user about the child. For instance, in my "children" table I have columns such as created_at and created_by that are only for record keeping, and don''t need to be displayed back to the user. I''m trying to find a simple way to only display selected columns from the "children" table. One way I can do it is by grabbing all the columns, and then only displaying the selected ones in the view: # in controller @children = Child.find_all_by_parent_id(@parent.id) In my view, I want to display the column names from left to right, and then the information for each child underneath: # in my list view <% for column in Child.content_columns %> <% if column.name == ''first_name'' || column.name == ''last_name'' ||column.name == ''gender'' %> <th><%= column.human_name %></th> <% end %> <% end %> <% for child in @children %> <% for column in Child.content_columns %> <% if column.name == ''first_name'' || column.name == ''last_name'' ||column.name == ''gender'' %> <td><%=h child.send(column.name) %></td> <% end %> <% end %> <% end %> This way will work, and only display the first_name, last_name, and gender column names and then assocated information of the child. However, this is rather complex when I want to display more information, and not very dynamic. Another way I''m looking into is only returning the selected columns that I want (some of the syntax might be off; I''m still trying to figure this part out): # in controller @children = Child.find_by_parent_id(@parent.id, :select => ''first_name'', ''last_name'', ''gender'') The syntax isn''t correct I don''t think, but the idea is there. I only want to select those 3 columns for each child who matches the parent''s id. Then, I want to display the column name and child information again: # in my list view <% for column in @children %> # lines where I''m having trouble <th><%= column.human_name %></th> <% end %> # list child information below column names <% for child in @children %> <% for column in child.columns %> <td><%=h child.send(column.name) %></td> <% end %> <% end %> This is essentially where I''m at right now. The problem is, once I''ve returned a list of the child objects to @children with only the selected columns (first_name, last_name, gender), how do I access just those columns and their names? I''m just looking for a simpler way to only display selected columns without having to have a bunch of "if" statements to check each column. Any help would be greatly appreciated. -Daniel -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
@children = Child.find_by_parent_id(@parent, :select => "first_name, last_name, gender") That should do it. Cam On Jun 12, 1:52 pm, Daniel Legrand <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Chris Hall wrote: > > Daniel, > > > I think you need to tell us how you are displaying your data. Rails > > by itself does not do any display by default unless you use > > scaffolding. if you are using scaffolding, it''s meant to be built > > upon (hence the name ''scaffolding'') and customized to your needs. > > > Chris > Chris Hall wrote: > > Daniel, > > > I think you need to tell us how you are displaying your data. Rails > > by itself does not do any display by default unless you use > > scaffolding. if you are using scaffolding, it''s meant to be built > > upon (hence the name ''scaffolding'') and customized to your needs. > > > Chris > > I have a "children" table that is assocated by "parent_id" to a > "parents" table. I want to display the children, but I only want to > display relevant information back to the user about the child. For > instance, in my "children" table I have columns such as created_at and > created_by that are only for record keeping, and don''t need to be > displayed back to the user. I''m trying to find a simple way to only > display selected columns from the "children" table. One way I can do it > is by grabbing all the columns, and then only displaying the selected > ones in the view: > > # in controller > @children = Child.find_all_by_parent_id(@parent.id) > > In my view, I want to display the column names from left to right, and > then the information for each child underneath: > > # in my list view > <% for column in Child.content_columns %> > <% if column.name == ''first_name'' || column.name == ''last_name'' > ||column.name == ''gender'' %> > <th><%= column.human_name %></th> > <% end %> > <% end %> > > <% for child in @children %> > <% for column in Child.content_columns %> > <% if column.name == ''first_name'' || column.name == ''last_name'' > ||column.name == ''gender'' %> > <td><%=h child.send(column.name) %></td> > <% end %> > <% end %> > <% end %> > > This way will work, and only display the first_name, last_name, and > gender column names and then assocated information of the child. > However, this is rather complex when I want to display more information, > and not very dynamic. Another way I''m looking into is only returning > the selected columns that I want (some of the syntax might be off; I''m > still trying to figure this part out): > > # in controller > @children = Child.find_by_parent_id(@parent.id, :select > => ''first_name'', ''last_name'', ''gender'') > > The syntax isn''t correct I don''t think, but the idea is there. I only > want to select those 3 columns for each child who matches the parent''s > id. Then, I want to display the column name and child information > again: > > # in my list view > <% for column in @children %> # lines where I''m having trouble > <th><%= column.human_name %></th> > <% end %> > > # list child information below column names > <% for child in @children %> > <% for column in child.columns %> > <td><%=h child.send(column.name) %></td> > <% end %> > <% end %> > > This is essentially where I''m at right now. The problem is, once I''ve > returned a list of the child objects to @children with only the selected > columns (first_name, last_name, gender), how do I access just those > columns and their names? I''m just looking for a simpler way to only > display selected columns without having to have a bunch of "if" > statements to check each column. Any help would be greatly appreciated. > -Daniel > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
well, part of the problem is that you are using content_columns to loop through your models attributes. i think you need to approach it from a different angle. it seems like you have this idea that everything is related somehow to column names and you need to break out of that mode of thinking. there really isn''t a need to use the content_columns approach, unless you see your database schema being dynamic. just hardcode the column names in the view and be done with it. Your model is the representation of what is in the database. Don''t think of it as columns in a record, think of it more as an object, which is what it is once you''ve retrieved the information from the database. once you do that you will see that it isn''t as difficult as you are making it out to be. for instance, what you will normally see is something like # in controller @children = Child.find_all_by_parent_id(@parent.id) # in view <tr><th>First</th><th>Last</th><th>Gender</th></tr> <% @children.each do |child| -%> <tr><td><%= child.first_name -%></td><td><%= child.last_name -%></td><td><%= child.gender -%></td> <% end -%> or better yet, use a partial <tr><th>First</th><th>Last</th><th>Gender</th></tr> <%= render :partial => ''child'', :collection => @children -%> _child.rhtml (partial) <tr> <td><%= child.first_name -%></td> <td><%= child.last_name -%></td> <td><%= child.gender -%></td> </tr> On 6/12/07, cammo <mvpaustralia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > @children = Child.find_by_parent_id(@parent, :select => "first_name, > last_name, gender") > > That should do it. > > Cam > > On Jun 12, 1:52 pm, Daniel Legrand <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Chris Hall wrote: > > > Daniel, > > > > > I think you need to tell us how you are displaying your data. Rails > > > by itself does not do any display by default unless you use > > > scaffolding. if you are using scaffolding, it''s meant to be built > > > upon (hence the name ''scaffolding'') and customized to your needs. > > > > > Chris > > Chris Hall wrote: > > > Daniel, > > > > > I think you need to tell us how you are displaying your data. Rails > > > by itself does not do any display by default unless you use > > > scaffolding. if you are using scaffolding, it''s meant to be built > > > upon (hence the name ''scaffolding'') and customized to your needs. > > > > > Chris > > > > I have a "children" table that is assocated by "parent_id" to a > > "parents" table. I want to display the children, but I only want to > > display relevant information back to the user about the child. For > > instance, in my "children" table I have columns such as created_at and > > created_by that are only for record keeping, and don''t need to be > > displayed back to the user. I''m trying to find a simple way to only > > display selected columns from the "children" table. One way I can do it > > is by grabbing all the columns, and then only displaying the selected > > ones in the view: > > > > # in controller > > @children = Child.find_all_by_parent_id(@parent.id) > > > > In my view, I want to display the column names from left to right, and > > then the information for each child underneath: > > > > # in my list view > > <% for column in Child.content_columns %> > > <% if column.name == ''first_name'' || column.name == ''last_name'' > > ||column.name == ''gender'' %> > > <th><%= column.human_name %></th> > > <% end %> > > <% end %> > > > > <% for child in @children %> > > <% for column in Child.content_columns %> > > <% if column.name == ''first_name'' || column.name == ''last_name'' > > ||column.name == ''gender'' %> > > <td><%=h child.send(column.name) %></td> > > <% end %> > > <% end %> > > <% end %> > > > > This way will work, and only display the first_name, last_name, and > > gender column names and then assocated information of the child. > > However, this is rather complex when I want to display more information, > > and not very dynamic. Another way I''m looking into is only returning > > the selected columns that I want (some of the syntax might be off; I''m > > still trying to figure this part out): > > > > # in controller > > @children = Child.find_by_parent_id(@parent.id, :select > > => ''first_name'', ''last_name'', ''gender'') > > > > The syntax isn''t correct I don''t think, but the idea is there. I only > > want to select those 3 columns for each child who matches the parent''s > > id. Then, I want to display the column name and child information > > again: > > > > # in my list view > > <% for column in @children %> # lines where I''m having trouble > > <th><%= column.human_name %></th> > > <% end %> > > > > # list child information below column names > > <% for child in @children %> > > <% for column in child.columns %> > > <td><%=h child.send(column.name) %></td> > > <% end %> > > <% end %> > > > > This is essentially where I''m at right now. The problem is, once I''ve > > returned a list of the child objects to @children with only the selected > > columns (first_name, last_name, gender), how do I access just those > > columns and their names? I''m just looking for a simpler way to only > > display selected columns without having to have a bunch of "if" > > statements to check each column. Any help would be greatly appreciated. > > -Daniel > > > > -- > > Posted viahttp://www.ruby-forum.com/. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---