I'm following a tutorial on how to create a Ruby-on-Rails blogging website with comments and tags, and have put my work so far on https://github.com/khpeek/jumpstart-blogger/.
The last part of the tutorial involves allowing authors to create user names and passwords. One of the pages is a default listing of the authors from the "sorcery" gem:
As you can see, there are blank columns with "Password" and "Password confirmation", which I'd like to remove.
The appearance of this page is governed by app/views/authors/index.html.erb, which reads
<p id="notice"><%= notice %></p>
<h1>Listing Authors</h1>
<table>
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Password</th>
<th>Password confirmation</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #authors.each do |author| %>
<tr>
<td><%= author.username %></td>
<td><%= author.email %></td>
<td><%= author.password %></td>
<td><%= author.password_confirmation %></td>
<td><%= link_to 'Show', author %></td>
<td><%= link_to 'Edit', edit_author_path(author) %></td>
<td><%= link_to 'Destroy', author, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Author', new_author_path %>
My thought was to comment out the lines
<th>Password</th>
<th>Password confirmation</th>
and
<td><%= author.password %></td>
<td><%= author.password_confirmation %></td>
However, if I do this, some text gets placed outside the main bounding box:
Is it possible to tell from this limited portion of the code what is going wrong here?
It happens because you have no style to "tell" your table to fill the full width.
Try adding the following stylesheet:
<style>
table { width: 100%; }
</style>
Related
On my index page, I succeeded in listing all of my 'games' in a table, unfortunately, another list, that isn't part of my index.html.erb file code also appears, above my table.
I don't understand how this is possible as my html file doesn't contain any element at the place the list appears on the browser... If someone has an idea that would be very nice !
Here's a photo of what appears on the browser :
browser problem snapshot
Here's my index.html.erb code :
<div class="container full-height">
<div class="abs-center">
<table class="table">
<thead>
<tr>
<td colspan="6">GAMES</td>
</tr>
</thead>
<tbody>
<%= #games.reverse.each do |g| %>
<tr>
<td><%= g.id %></td>
<td><%= g.score_1 %></td>
<td><%= g.score_2 %></td>
<td><%= g.created_at %></td>
<td><%= link_to 'see game', game_path(g) %></td>
<td><%= link_to 'modify', edit_game_path(g) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
My game controller index method :
def index
#games = Game.all
end
Thanks a lot !
Remove = before <%= #games.reverse.each do |g| %>. = renders a result of an expression, in your case, it is each method, that returns the collection.
Must look as this <% #games.reverse.each do |g| %>
I just made a table and I have three records that I'm trying to display. It successfully displays the information but it crams it all in one row. When I want it to display over three rows. I'm doing something obvious wrong but I still need some help. Here is my code:
HTML
<table>
<tr>
<th>Name</th>
<th>Manage</th>
</tr>
<tr>
<% #assignments.each do |assignment| %>
<td><%= link_to assignment.name, account_assignment_path(assignment) %></td>
<td><%= link_to "Delete", account_assignment_path(assignment), method: :delete %></td>
<% end %>
</tr>
</table>
Screen Shot:
As you can see they all try to fit in one column. How can I fix this so they spread out?
I'm not familiar with the templating language you're using, but this is likely due to not including the <tr> element in your loop.
<table>
<tr>
<th>Name</th>
<th>Manage</th>
</tr>
<% #assignments.each do |assignment| %>
<tr>
<td><%= link_to assignment.name, account_assignment_path(assignment) %></td>
<td><%= link_to "Delete", account_assignment_path(assignment), method: :delete %></td>
</tr>
<% end %>
</table>
I am creating a Blog as my college project. Now i have a table named blogs and there are 5 attributes in the table.
blog_name, blog_user, blog_id, blog_date & blog_text
Now there are saveral entries in the blog.
I need a way to fetch the whole table and show the list of blog on a single page.
That is need a way to select the whole table and print the blog names using a while loop.
This is what you're looking for:
<% Blog.all.each do |blog| %>
# code
<% end %>
I'd also advice you learning some Ruby/Rails basics.
You can do like this
In your Controller
def index
#blog = Blog.all
end
In your view(index.html.erb)
<table border=1>
<tr>
<th>Blog Name</th>
<th>Blog User</th>
<th>Blog ID</th>
<th>Blog Date</th>
<th>Blog Text</th>
</tr>
<% #blog.each do |b| %>
<tr>
<td><%= b.blog_name %></td>
<td><%= b.blog_user %></td>
<td><%= b.blog_id %></td>
<td><%= b.blog_date %></td>
<td><%= b.blog_text %></td>
</tr>
<% end %>
</table>
So,for every blog entry you will be getting all the details populated in a table view.
I have the following code in an ERB file:
<table border="1">
<% #lists.each do |list| %>
<tr class="even">
<td><%= link_to list.title, list %></td>
<td><%= link_to 'Edit', edit_list_path(list) %></td>
<td><%= button_to "Destroy", list_path(list), :method => :delete %></td>
</tr>
<% end %>
</table>
I want to make the <tr class="even" line dynamic. Each tr should get the class either "even" or "odd" depending on a counter variable that gets incremented every time my loop starts over. However, I cannot figure out the best way to implement this.
Use this nice helper :)
<tr class="<%= cycle("even", "odd") %>">
I'd like to view data from different database-tables in a view with tables like this picture shows:
I'm familiar with HTML tags <table>, <td> and <tr>, but I'm having trouble with multiple queries in a column.
<table>
<tr>
<th>Skills </th>
<th>Expected-qualifications</th>
<th>Current-qualifications</th>
</tr>
<% #employee.position.skills.each do |skill| %><% #employee.position.expected_qualifications.each do |expected_qualification| %><% #employee.current_qualifications.each do |current_qualification| %>
<tr>
<td><%= skill.kategorien %></td>
<td><%= expected_qualification.sollqualifikation %></td>
<td><%= current_qualification.istqualifikation %></td>
</tr>
<% end %><% end %><% end %>
</table>
This code looks like this:
As you can see, the skills, expected-qualifications, and current-qualifications repeat.
My question: How should the codes be ordered in the table so it will look the way I want it to?
Try zip:
<% #employee.position.skills.zip(#employee.position.expected_qualifications,#employee.current_qualifications).each |skill expected_qualification current_qualification| %>
<tr>
<td><%= skill.kategorien %></td>
<td><%= expected_qualification.sollqualifikation %></td>
<td><%= current_qualification.istqualifikation %></td>
</tr>
<% end %>
if there is REALLY can be more than one skill, expected_qualification and current_qualification so you use has_many assosiation forposition
<tr>
<td><%= #employee.position.skills.map(&:kategorien).join(", ") %></td>
<td><%= #employee.position.expected_qualifications.map(&:sollqualifikation).join(", ") %></td>
<td><%= #employee.current_qualifications.map(&:istqualifikation).join(", ") %></td>
</tr>
Otherwise you should use has_one association