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;
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
add a comment
|
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
add a comment
|
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
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
html ruby-on-rails ruby
edited Mar 28 at 19:13
Joshua Hedges
asked Mar 28 at 19:01
Joshua HedgesJoshua Hedges
9610 bronze badges
9610 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment
|
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
add a comment
|
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
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
answered Mar 28 at 19:31
chumakoffchumakoff
4,8411 gold badge15 silver badges35 bronze badges
4,8411 gold badge15 silver badges35 bronze badges
add a comment
|
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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