How do I create a html helper table function in rails?Why not use tables for layout in HTML?How can I “pretty” format my JSON output in Ruby on Rails?How can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How to redirect to a 404 in Rails?How to drop columns using Rails migrationHow to create an HTML button that acts like a link?How can I set the default value for an HTML <select> element?How to create a checkbox with a clickable label?How do I reformat HTML code using Sublime Text 2?

Where is the bomb: How to estimate the probability, given row and column totals?

What in my code changed between MacTeX 2017 and MacTex 2019?

Is determiner 'a' needed here?

When did Unix stop storing passwords in clear text?

Why is a road bike faster than a city bike with the same effort? How much faster it can be?

How can I find Marin?

I reverse the source code, you reverse the input!

I transpose the source code, you transpose the input!

Is it ok if I haven't decided my research topic when I first meet with a potential phd advisor?

what organs or modifications would be needed to have hairy fish?

Can I exile my opponent's Progenitus/True-Name Nemesis with Teferi, Hero of Dominaria's emblem?

What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?

Read-once memory

Why isn't there armor to protect from spells in the Potterverse?

Sci-fi movie with one survivor and an organism(?) recreating his memories

How do my husband and I get over our fear of having another difficult baby?

Kinematic formula for Euler characteristic

How fast can a LN payment be over TOR?

Why is STARTTLS still used?

is there a relationship between prime numbers and music?

An impressive body of work

Whaling ship logistics

How come it seems the best way to make a living is to invest in real estate?

As a team leader is it appropriate to bring in fundraiser candy?



How do I create a html helper table function in rails?


Why not use tables for layout in HTML?How can I “pretty” format my JSON output in Ruby on Rails?How can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How to redirect to a 404 in Rails?How to drop columns using Rails migrationHow to create an HTML button that acts like a link?How can I set the default value for an HTML <select> element?How to create a checkbox with a clickable label?How do I reformat HTML code using Sublime Text 2?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to create helper methods in my ruby to make a table like this:



<table>
<legend>Test Table</legend>
<thead>
<th>name</th>
<th>age</th>
<th>occupation</th>
</thead>
<tbody>
<tr><td>Josh</td><td>32</td><td>Ditch Digger</td></tr>
<tr><td>John</td><td>54</td><td>Burger Flipper</td></tr>
<tr><td>Jake</td><td>21</td><td>Couch Potato</td></tr>
</tbody>
</table>


My data is a ruby hash that sort of looks like this:



root
users
'name'=>'Josh', 'age'=>'32','job'=>'Ditch Digger',
'name'=>'John', 'age'=>'54','job'=>'Burger Flipper',
'name'=>'Jake', 'age'=>'21','job'=>'Couch Potato'


An attempt at a function to make this table



def data_table_personnel(source)
if subdata = source&.dig('root', 'users')
h.content_tag :table do
h.content_tag :tr do
h.content_tag :td subdata.name
h.content_tag :td subdata.age
h.content_tag :td subdata.job
end
end
end
end
end


I'm making a lot of tables in my project, so I'd like to avoid ERB if possible.










share|improve this question
































    0















    I want to create helper methods in my ruby to make a table like this:



    <table>
    <legend>Test Table</legend>
    <thead>
    <th>name</th>
    <th>age</th>
    <th>occupation</th>
    </thead>
    <tbody>
    <tr><td>Josh</td><td>32</td><td>Ditch Digger</td></tr>
    <tr><td>John</td><td>54</td><td>Burger Flipper</td></tr>
    <tr><td>Jake</td><td>21</td><td>Couch Potato</td></tr>
    </tbody>
    </table>


    My data is a ruby hash that sort of looks like this:



    root
    users
    'name'=>'Josh', 'age'=>'32','job'=>'Ditch Digger',
    'name'=>'John', 'age'=>'54','job'=>'Burger Flipper',
    'name'=>'Jake', 'age'=>'21','job'=>'Couch Potato'


    An attempt at a function to make this table



    def data_table_personnel(source)
    if subdata = source&.dig('root', 'users')
    h.content_tag :table do
    h.content_tag :tr do
    h.content_tag :td subdata.name
    h.content_tag :td subdata.age
    h.content_tag :td subdata.job
    end
    end
    end
    end
    end


    I'm making a lot of tables in my project, so I'd like to avoid ERB if possible.










    share|improve this question




























      0












      0








      0








      I want to create helper methods in my ruby to make a table like this:



      <table>
      <legend>Test Table</legend>
      <thead>
      <th>name</th>
      <th>age</th>
      <th>occupation</th>
      </thead>
      <tbody>
      <tr><td>Josh</td><td>32</td><td>Ditch Digger</td></tr>
      <tr><td>John</td><td>54</td><td>Burger Flipper</td></tr>
      <tr><td>Jake</td><td>21</td><td>Couch Potato</td></tr>
      </tbody>
      </table>


      My data is a ruby hash that sort of looks like this:



      root
      users
      'name'=>'Josh', 'age'=>'32','job'=>'Ditch Digger',
      'name'=>'John', 'age'=>'54','job'=>'Burger Flipper',
      'name'=>'Jake', 'age'=>'21','job'=>'Couch Potato'


      An attempt at a function to make this table



      def data_table_personnel(source)
      if subdata = source&.dig('root', 'users')
      h.content_tag :table do
      h.content_tag :tr do
      h.content_tag :td subdata.name
      h.content_tag :td subdata.age
      h.content_tag :td subdata.job
      end
      end
      end
      end
      end


      I'm making a lot of tables in my project, so I'd like to avoid ERB if possible.










      share|improve this question
















      I want to create helper methods in my ruby to make a table like this:



      <table>
      <legend>Test Table</legend>
      <thead>
      <th>name</th>
      <th>age</th>
      <th>occupation</th>
      </thead>
      <tbody>
      <tr><td>Josh</td><td>32</td><td>Ditch Digger</td></tr>
      <tr><td>John</td><td>54</td><td>Burger Flipper</td></tr>
      <tr><td>Jake</td><td>21</td><td>Couch Potato</td></tr>
      </tbody>
      </table>


      My data is a ruby hash that sort of looks like this:



      root
      users
      'name'=>'Josh', 'age'=>'32','job'=>'Ditch Digger',
      'name'=>'John', 'age'=>'54','job'=>'Burger Flipper',
      'name'=>'Jake', 'age'=>'21','job'=>'Couch Potato'


      An attempt at a function to make this table



      def data_table_personnel(source)
      if subdata = source&.dig('root', 'users')
      h.content_tag :table do
      h.content_tag :tr do
      h.content_tag :td subdata.name
      h.content_tag :td subdata.age
      h.content_tag :td subdata.job
      end
      end
      end
      end
      end


      I'm making a lot of tables in my project, so I'd like to avoid ERB if possible.







      html ruby-on-rails ruby






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 19:13







      Joshua Hedges

















      asked Mar 28 at 19:01









      Joshua HedgesJoshua Hedges

      9610 bronze badges




      9610 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1
















          def data_table_personnel(source)
          users = source&.dig('root', 'users')
          return if users.blank?

          h.content_tag :table do
          users.map do |user|
          # generate '<tr>' for each user
          h.content_tag :tr do
          [:name, :age, :job].map do |attr|
          # generate '<td>' for each user attribute
          h.content_tag :td user[attr]
          end.join # join <td>s
          end
          end.join # join <tr>s
          end
          end





          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405080%2fhow-do-i-create-a-html-helper-table-function-in-rails%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1
















            def data_table_personnel(source)
            users = source&.dig('root', 'users')
            return if users.blank?

            h.content_tag :table do
            users.map do |user|
            # generate '<tr>' for each user
            h.content_tag :tr do
            [:name, :age, :job].map do |attr|
            # generate '<td>' for each user attribute
            h.content_tag :td user[attr]
            end.join # join <td>s
            end
            end.join # join <tr>s
            end
            end





            share|improve this answer





























              1
















              def data_table_personnel(source)
              users = source&.dig('root', 'users')
              return if users.blank?

              h.content_tag :table do
              users.map do |user|
              # generate '<tr>' for each user
              h.content_tag :tr do
              [:name, :age, :job].map do |attr|
              # generate '<td>' for each user attribute
              h.content_tag :td user[attr]
              end.join # join <td>s
              end
              end.join # join <tr>s
              end
              end





              share|improve this answer



























                1














                1










                1









                def data_table_personnel(source)
                users = source&.dig('root', 'users')
                return if users.blank?

                h.content_tag :table do
                users.map do |user|
                # generate '<tr>' for each user
                h.content_tag :tr do
                [:name, :age, :job].map do |attr|
                # generate '<td>' for each user attribute
                h.content_tag :td user[attr]
                end.join # join <td>s
                end
                end.join # join <tr>s
                end
                end





                share|improve this answer













                def data_table_personnel(source)
                users = source&.dig('root', 'users')
                return if users.blank?

                h.content_tag :table do
                users.map do |user|
                # generate '<tr>' for each user
                h.content_tag :tr do
                [:name, :age, :job].map do |attr|
                # generate '<td>' for each user attribute
                h.content_tag :td user[attr]
                end.join # join <td>s
                end
                end.join # join <tr>s
                end
                end






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 19:31









                chumakoffchumakoff

                4,8411 gold badge15 silver badges35 bronze badges




                4,8411 gold badge15 silver badges35 bronze badges

































                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405080%2fhow-do-i-create-a-html-helper-table-function-in-rails%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해