Rubymine warns header partial HTML with "element table is not close" - ruby-on-rails

I have view files like these:
comments/_comment.html.erb
<tr>
<td><%= comment.author %></td>
<td><%= comment.text %></td>
</tr>
comments/_table_header.html.erb
<table>
<thead>
<tr>
<td>Author</td>
<td>Text</td>
</tr>
</thead>
<tbody>
comments/_table_footer.html.erb
</tbody>
</table>
Then I got warning "element table is not close" by RubyMine.
Is there a better way to write table this?
If there is not, is there a way to suppress the warning only when the file name includes _header or _footer?
I want keep active this warning itself for other files.

Use a _table.html.erb partial and don't split it up into header and footer.
comments/_table.html.erb
<table>
<thead>
<tr>
<td>Author</td>
<td>Text</td>
</tr>
</thead>
<tbody>
<%= render #comments %> <!-- Rails magic here! -->
</tbody>
</table>
comments/_comment.html.erb
<tr>
<td><%= comment.author %></td>
<td><%= comment.text %></td>
</tr>

Related

Creating large bootstrap table in Ruby on Rails

Hi I am a little new to Ruby on Rails and this should be pretty simple. I want to make a large bootstrap table, while also being able to loop through my model/database table.
<table class="table">
<thead>
<tr>
<th scope="col">I</th>
<th scope="col">Id</th>
<th scope="col">Time</th>
<th scope="col">Duration</th>
<th scope="col">Price</th>
<th scope="col">Name</th>
<th scope="col">Company</th>
<th scope="col">City</th>
</tr>
</thead>
<tbody>
<% 96.times |i| %>
<% #workorders.each do |workorder| %>
<tr>
<td><%= i %></td>
<td><%= workorder.id %></td>
<td><%= workorder.time %></td>
<td><%= workorder.duration %></td>
<td><%= workorder.price %></td>
<td><%= workorder.name %></td>
<td><%= workorder.company %></td>
<td><%= workorder.city %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
I have verified that when I do just a .each loop over #workorders it works fine. However, when I run my Rails application with the above code I get a syntax error, nothing too detailed. What would be the proper syntax to create this 96-length bootstrap table, while also looping through my model/sqlite table?
Brilliant! Thank you so much! Adding a do after 96.times solved everything.

Nested loop in table ruby on rails 6 view wrong order

I have a category, which has work registrations. To show these in a table i use code below. However it gets executed in the wrong way. All categories are printed in the top of the table, while all work registrations are then posted below the list of categories. This is strange to me, as the work registrations loop is executed in the category loop. Any idea how to correct the code? I tried using group_by, however this gives the same result.
<table id="dataWorkRegistrations" class="table table-lightborder" data-class="WorkRegistration">
<thead>
<tr>
<th><%= t('work_registration.fields.code.label') %></th>
<th><%= t('work_registration.fields.status.label') %></th>
<th><%= t('work_registration.fields.name.label') %></th>
<th><%= t('work_registration.fields.frequency.label') %></th>
<th><%= t('work_registration.fields.amount.label') %></th>
</tr>
</thead>
<tbody>
<% #categories.each do |categorie| %>
<tr class='bg-light'>
<td><b><%= categorie.code %></b></td>
<td> </td>
<td><b><%= categorie.name %></b></td>
<td> </td>
<td> </td>
</tr>
<% categorie.work_registrations.each do |work_registration| %>
<tr>
<td><%= work_registration.code %></td>
<td><%= work_registration.status %></td>
<td><%= work_registration.name %></td>
<td><%= work_registration.frequency %></td>
<td><%= work_registration.amount %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
I managed to solve the problem. As the table as an index for work_registrations. Datatables started to sort all, which caused the strange sorting. After disabling initial sorting on datatable, it worked instant.

how to display one controller show action in another controller action in rails

I am using two controller incident and incident_list, i am displaying all incidents in incident_list/index page when click on show button in each incident i want to display that incident details
IncidentListController
def show
#incidents = Incident.all
#incident = Incident.find(params[:id])
render "incidents/show"
end
IncidentController
def show
#incidents = Incident.all
#incident = Incident.find(params[:id])
end
incidnet_lists/index.html.erb
<table>
<table class="table table-striped table-bordered">
<thead >
<tr>
<th class="c2">Case ID</th>
<th class="c2">Call Type</th>
<th class="c2">Number of People</th>
<th class="c2"></th>
</tr>
</thead>
<tbody>
<tr>
<td><%= inc.id %> </td>
<td><%= inc.call_type %> </td>
<td><%= inc.no_of_people %></td>
<td><%= link_to 'Show', #incidents %></td>
</tr>
</tbody>
</table>
incidents/show.html.erb
<table class="table table-striped table-bordered">
<thead>
<tr>
<td class= "c2" > Case Id </td>
<td class= "c2"> Caller Name </td>
<td class="c2"> Contact Number </td>
<td class= "c2"> Calling For </td>
<td class="c2"> Call Type </td>
<tr>
</thead>
<tbody>
<% #incidents.each do |inc| %>
<tr>
<td> <%= inc.id %> </td>
<td> <%= inc.caller_name %></td>
<td> <%= inc.contact_number %></td>
<td> <%= inc.for_whom %> </td>
<td> <%= inc.call_type %> </td>
</tr>
<% end %>
</tbody>
</table>
when click on show button in the incident_list page incident show page should be display
Your situation is perfectly covered by REST approach.
According to that approach you should have the single IncidentsController controller. Then you should have
show action which would expose particular incident to show.html.erb view as #incident instance variable
index action which would expose the list of all (or some) incidents to index.html.erb view as #incidents instance variable.
So you don't need and should not call some controller's action from another controller's action.
It's the "Rails Way", it's the "REST Way". It's the way how one should do that.
The simplest tip in your situation is generate rails scaffold for your incidents resources and use the generated files properly to set up things.
rails generate scaffold Incident

search the contents of a table in rails

I want to place a searchbox on my table to filter it according to eventtitle.
Any ideas how I can go about this? I've tried two tutorials but it didn't work. I've also tried the filterrific gem but it didnt work either.
So far I just have this loading my table in the controller
#newevents = Event.order("id").page(params[:page]).per(50)
And this in my view
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>EventName</th>
<th>Date</th>
<th>Time</th>
<th>Link</th>
</tr>
</thead>
<tbody>
<% #newevents.each do |ne| %>
<% if ne.eventready.blank?%>
<tr>
<td><%= ne.id %></td>
<td><%= ne.eventname %></td>
<td><%= ne.date %></td>
<td><%= ne.time %></td>
<td><%= link_to "Edit Event", edit_event_path(ne.id), class: "btn btn-info" %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<%= paginate #newevents %>

App deployment to heroku does not show dynamic contents on the page

Hi i am new to web development, learning and working on rails 4.2.4 version. I have created a simple blog app that is working absolutely fine on local server, but when i tried to push it on HEROKU only my static are visible on page but not the dynamic contents . where might i be making mistake.please help below is my code for index view.
<table>
<thead>
<tr>
<th>Title</th>
<th>Body</th>
<th>Category</th>
<th>Author</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #posts.each do |post| %>
<tr>
<td><%= link_to post.title, post %></td>
<td><%= post.body %></td>
<td><%= post.category_id %></td>
<td><%= post.author_id %></td>
</tr>
<% end %>
</tbody>
</table>
<br>

Resources