SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Excluding table columns from List view

    I am fairly new to ROR and am trying to edit the default scaffolds for my new application. I have like 30 columns in my database and I only want to display about 3 of them in the list.rhtml view. I am stuck and wondering how to achieve this. Any help would be greatly appreciated.

    My list.rhtml view code looks like this:

    Code Ruby:
    <% for column in WellProfile.content_columns %>
        <th><%= column.human_name %></th>
       <% end %>
      </tr>
    <% for well_profile in @well_profiles %>
      <tr>
      <% for column in WellProfile.content_columns %>
       <td><%=h well_profile.send(column.name) %></td>
      <% end %>

    And controller code like so:

    Code Ruby:
    def list
        @well_profile_pages, @well_profiles = paginate :well_profiles, :per_page => 10
      end

    Thanks!
    Web design is cool. Roll with it.

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out. I was making things too complex. The solution was too simple to believe

    I just had to take out the content_columns and replace each column with something like this:
    <&#37;=h well_profile["well_name"] %>
    Web design is cool. Roll with it.

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi VannSystems,

    You are probably better off doing <&#37;h well_profile.well_name %> because you can alias those as methods if you ever need to change database structures of add any additional logic before displaying. I know it's in the "That probably won't happen" category, but it is a good habit to get in to

    Last edited by madpilot; Oct 17, 2007 at 03:19. Reason: Typos

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Location
    Texas
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks madpilot. I made the change. I am all about sticking to solid design principles. I appreciate the correction.
    Web design is cool. Roll with it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •