Missing Partial for render in rails - ruby-on-rails

I create partial which calling _topics_list.form.html.erb and have some code
<table class="list" cellspaceing="0">
<thead class="head_list">
<tr>
<th class="column">Name</th>
<th class="column">Description</th>
</tr>
</thead>
<% #topics.each do |topic| %>
<tr class="row">
<td data-label="Name" class="column first"><%= topic.name %></td>
<td data-label="Description" class="column column_problem">
<%= link_to topic.description, topic_path(topic), class:"link_for_column_problem" %>
</td>
<td data-label="Date" class="column"><%= topic.created_at.strftime("%d %b, %Y") %></td>
</tr>
<% end %>
</table>
Also I connect this partial with my index-file by <%= render 'topics_list'%>
When I try it I have error
Missing partial topics/_topics_list, application/_topics_list with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :arb, :jbuilder]}. Searched in:
* "/home/dse/BlackListV2/app/views"
* "/home/dse/.rvm/gems/ruby-2.7.0/gems/activeadmin-2.6.1/app/views"
* "/home/dse/.rvm/gems/ruby-2.7.0/gems/kaminari-core-1.2.0/app/views"
* "/home/dse/.rvm/gems/ruby-2.7.0/gems/devise-4.7.1/app/views"
* "/home/dse/.rvm/gems/ruby-2.7.0/gems/actiontext-6.0.2.1/app/views"
* "/home/dse/.rvm/gems/ruby-2.7.0/gems/actionmailbox-6.0.2.1/app/views"
UPDATE
<p id="notice"><%= notice %></p>
<h1 class="request_headline">All Topics</h1>
<%= render 'topics_list'%>
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #topics.each do |topic| %>
<tr>
<td><%= link_to 'Show', topic %></td>
<td><%= link_to 'Edit', edit_topic_path(topic) %></td>
<td><%= link_to 'Destroy', topic, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Topic', new_topic_path %>
Code where I render partial

Your partial name is _topics_list.form.html.erb. To render this, you need to call render 'topics_list.form', not render 'topics_list'.

Try changing
<p id="notice"><%= notice %></p>
<h1 class="request_headline">All Topics</h1>
<%= render 'topics_list'%>
to
<p id="notice"><%= notice %></p>
<h1 class="request_headline">All Topics</h1>
<%= render 'topics/topics_list' %>
Also, a good idea will be to always pass local variables to partials instead of using global variables, that way you have an absolute control over values in partials.
<%= render 'topics/topics_list', topics: #topics %>
and then in partial use
<table class="list" cellspaceing="0">
<thead class="head_list">
<tr>
<th class="column">Name</th>
<th class="column">Description</th>
</tr>
</thead>
<% topics.each do |topic| %>
<tr class="row">
.....
.....
</tr>
<% end %>
</table>

Related

how to call a all checkbox ids in select/deselect all checkbox in ror application?

I am trying to add select/deselect all checkbox (I tried click the select all and delete the records(all) in my table) in my ror application. If I click the Select all checkbox, all checkboxes in the table are not selected, at the same time delete method are also not called.
Here my Controller file:
def destroy
#messages = Message.where(id: params[:message_ids])
#messages.destroy_all
respond_to do |format|
format.html { redirect_to messages_url, notice: 'Message was successfully destroyed.' }
format.json { head :no_content }
end
end
I am using jquery code in index.html.erb file itself. Here it is:
<p id="notice"><%= notice %></p>
<h1>Messages</h1>
<table>
<thead>
<tr>
<th ><%= check_box_tag "message_ids[]",class: 'selectall' %></th>
<th>Content</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<%= form_tag messages_path, method: :delete do %>
<% #messages.each do |message| %>
<tr>
<td><%= check_box_tag "message_ids[]", message.id%></td>
<td><%= message.content %></td>
<td><%= link_to 'Show', message %></td>
<td class="edititem"><%= link_to 'Edit', edit_message_path(message)%></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= submit_tag :Delete,class: 'btn' %>
</br>
<% end %>
<br>
<%= link_to 'New Message', new_message_path %>
</br>
<script>
$('#selectall').click(function(event) {
if (this.message_ids) {
$(':checkbox').attr('message_ids', true);
} else {
$(':checkbox').attr('message_ids', false);
}
});
</script>
I am a beginner, Please Help me to solve my issue....
Try something like
$(".selectall").click(function () {
$('#my-table tbody input[type="checkbox"]').prop('checked', this.checked);
});
$('.selectall').toggle(function(){
$('#my-table tbody input[type="checkbox"]').attr('checked','checked');
},function(){
$('#my-table tbody input[type="checkbox"]').removeAttr('checked');
});
1=> provide a id (id: 'select_all_messages')on which click trigger all checkbox checked.
2=> provide a common class on all checkbox of message which will be triggered on click id: select_all_messages
like =>
<table>
<thead>
<tr>
<th ><%= check_box_tag "select_all",id: 'select_all_messages' %></th>
<th>Content</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<%= form_tag messages_path, method: :delete do %>
<% #messages.each do |message| %>
<tr>
<td><%#= check_box_tag "message_ids[]", message.id, class: 'check_uncheck_message'%></td>
<td><%= check_box_tag "message_ids[]",message.id,false, class: 'check_uncheck_message'%></td>
<td><%= message.content %></td>
<td><%= link_to 'Show', message %></td>
<td class="edititem"><%= link_to 'Edit', edit_message_path(message)%></td>
</tr>
<% end %>
</tbody>
</table>
<script type="text/javascript">
$("#select_all_messages").on('click', function () {
$('.check_uncheck_message').prop('checked', this.checked);
//$('.check_uncheck_message').prop("checked", true);
});
</script>

Rails 5 - table row while no entry exists

In my rails app, content of documents are being tagged. For documents that do not have any tags, an empty row is shown in the listing (table rows) - always at the bottom of the table. I've tried to solve this for hours, not sure where to research and I'm not getting anywhere. All help welcome!
this is the view (snippet):
<div class="row" id="annotationResults">
<div class="panel panel-default" style="background-color: white; word-wrap: break-word; font-size: 0.9em;">
<table id="tags" class="table table-hover">
<thead>
<tr>
<th>Tagged content</th>
<th>as</th>
<th>in</th>
<th></th>
</tr>
</thead>
<tbody>
<% #annotation.tags.each do |tag| %>
<tr>
<td><%= tag.content %></td>
<td><%= tag.tagtype_id %></td>
<td><%#= tag.tagtype.name %></td>
<td><%= link_to '', [tag.annotation, tag], method: :delete, data: { confirm: 'Please confirm deletion!' }, :class => "glyphicon glyphicon-remove" %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
It's there because you're printing an empty td.
<td><%= tag.content %></td>
Will print the td element even if the tag.content is empty. Check the example:
td{ border: 1px solid black }
<table>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
Use your RoR snippet as you mentioned in the comment:
<% #annotation.tags.each do |tag| %>
<% unless tag.content.blank? %>
<td>
<!-- logic -->
</td>
<% end %>
<% end %>
try this,
<% if tag.content.present? %>
<%= tag.content %>
<% end %>

Layout not rendering properly as expected

In my index action I have
#posts = Post.all
This is my index.html.erb.
<div class="row">
<div class="columns large-12 small-12 medium-12">
</div>
<p id="notice"><%= notice %></p>
<h1>Listing Posts</h1>
<table>
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Body</th>
<th>Body</th>
<th>Body</th>
<th>Body</th>
</tr>
</thead>
<tbody>
<%= #posts.each do |post| %>
<tr>
<td> <%= post.id %> </td>
<td> <%= post.title %> </td>
<td> <%= post.body %> </td>
<td > <%= link_to 'Show' %> </td>
<td > <%= link_to 'Edit', edit_post_path(post) %> </td>
<td> <%= link_to 'Destroy', post, method: :delete %> </td>
</tr>
<% end %>
</tbody>
</table>
<%= link_to 'NEW POST', new_post_path %>
</div>
It is rendering fine except that the #posts object is printing in a form like below just above the table tag in my browser. I know it is something silly but I can't figure that out.
[#<Post id: 4, title: "new title", body: "this is new body", created_at: "2015-12-21 07:44:42", updated_at: "2015-12-21 10:31:31">, #<Post id: 7, title: "new title", body: "dfdsfd", created_at: "2015-12-21 09:40:01", updated_at: "2015-12-21 09:40:01">]
Turns out it was something really really silly! The erb template engine requires = with erb tags to display the data while the logic is written without using the =.
It was just a simple change like this:
<% #posts.each do |post| %> # without the = symbol
hai just remove the '=' in the #posts.each line.
<%#posts.each do |post| %>, thats it.
<div class="row">
<div class="columns large-12 small-12 medium-12">
</div>
<p id="notice"><%= notice %></p>
<h1>Listing Posts</h1>
<table>
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Body</th>
<th>Body</th>
<th>Body</th>
<th>Body</th>
</tr>
</thead>
<tbody>
<% #posts.each do |post| %>
<tr>
<td> <%= post.id %> </td>
<td> <%= post.title %> </td>
<td> <%= post.body %> </td>
<td > <%= link_to 'Show' %> </td>
<td > <%= link_to 'Edit', edit_post_path(post) %> </td>
<td> <%= link_to 'Destroy', post, method: :delete %> </td>
</tr>
<% end %>
</tbody>
</table>
<%= link_to 'NEW POST', new_post_path %>
</div>

Ruby display array values

I am not a ruby developer. This is the first time I am looking into the code. I want to build a dynamic table for which I have managed below code. However, I am not able to display all the contents of the array except for the first and the last values. How do I display all the values?
Thanks for your help!!
<style>table, td, th{border:1px solid white;}td{padding:5px;}th{background-color:#E0E6EB;color:black;}</style>
<div>
<table border=2>
<tr>
<th width="250px"><B><p style="text-align: center">Name</p></B></th>
<th width="120px"><B><p style="text-align: center">Number</p></B></th>
<th width="60px"><B><p style="text-align: center">Status</p></B></th>
<th width="155px"><B><p style="text-align: center">Product Type</p></B></th>
<th width="60px"><B><p style="text-align: center">Source</p></B></th>
</tr>
<% tempTickets = #subject.PersonAccounts.sorted_by(field("title").in_descending_order) %>
<% cnt = tempTickets.length %>
<% tempTickets.each do |ticket| %>
<div>
<tr>
<td><%= ticket['perfinaccnt-accountname'].first %></td>
<td><%= ticket['perfinaccnt-accountnumber'].first %></td>
<td><%= ticket['perfinaccnt-accountstatus'].first %></td>
<td><%= ticket['perfinaccnt-producttype'].first %></td>
<td><%= ticket['perfinaccnt-accountsrcsystem'].first %></td>
</tr>
</div>
<div>
<tr>
<td><%= ticket['perfinaccnt-accountname'].last %></td>
<td><%= ticket['perfinaccnt-accountnumber'].last %></td>
<td><%= ticket['perfinaccnt-accountstatus'].last %></td>
<td><%= ticket['perfinaccnt-producttype'].last %></td>
<td><%= ticket['perfinaccnt-accountsrcsystem'].last %></td>
</tr>
</div>
<% end %>
</table>
</div>
You could do it with three nested loops:
<%= tempTickets.each do |ticket|
[
'perfinaccnt-accountname',
'perfinaccnt-accountnumber',
'perfinaccnt-accountstatus',
'perfinaccnt-producttype',
'perfinaccnt-accountsrcsystem'
].each do |f|
ticket[f].each do |tf|
puts "<td>tf</td>";
end if ticket[f]
end
end %>
I'm not sure about the data structure here but you could check it by doing an #inspect to tempTickets and all the subsequent objects. From the looks of it "ticket['perfinaccnt-accountname']" is actually an array
and as such you can just loop through it. Not the fastest way to do it but it should work to just do a nested loop.
<style>table, td, th{border:1px solid white;}td{padding:5px;}th{background-color:#E0E6EB;color:black;}</style>
<div>
<table border=2>
<tr>
<th width="250px"><B><p style="text-align: center">Name</p></B></th>
<th width="120px"><B><p style="text-align: center">Number</p></B></th>
<th width="60px"><B><p style="text-align: center">Status</p></B></th>
<th width="155px"><B><p style="text-align: center">Product Type</p></B></th>
<th width="60px"><B><p style="text-align: center">Source</p></B></th>
</tr>
<% tempTickets = #subject.PersonAccounts.sorted_by(field("title").in_descending_order) %>
<% cnt = tempTickets.length %>
<% tempTickets.each do |ticket| %>
<div><tr>
<% ticket.each do |k,v|
v.each do |col| %>
<td><%= col %></td>
<% end %>
<% end %>
</tr></div>
<% end %>
</table>
</div>

Print HTML Page Twitter bootstrap

I have a show page /invoices/show that displays contents of my Invoice
<p id="notice"><%= notice %></p>
<div class="row">
<div class="span7">
<h2 style="text-align:center;"> CONSTRUCTION LTD </h2>
<h3 style="text-align:center;">OHIO</h3>
<address style="text-align:center;"> Plot 10<br/>
</address>
<h3 style="text-decoration:underline; text-align:center;"> UTILITY BILL </h3>
<h4 style="text-decoration:underline; text-align:center;"> TAX INVOICE </h4>
<table>
<td valign="top" align="left">
<div style="float:left; width:450px;">No: <%= #invoice.id %></div>
<div style="float:right"> Date: <%= #invoice.invoice_date %></div>
</td>
</table>
<P></P>
<P></P>
<div>To: <%= #invoice.customer.name%></div>
<p></p>
<table class="table table-bordered table-condensed">
<thead>
<tr class="success">
<th><label class="control-label">Description</label></th>
<th><label class="control-label">Rate</label></th>
<th><label class="control-label">Tax</label></th>
<th><label class="control-label">Amount</label></th>
</tr>
</thead>
<tbody>
<% #invoice.invoice_items.each do | item| %>
<tr class="controls">
<td><%= item.description %></td>
<td><%= item.rate %></td>
<td><%= item.tax_amount %></td>
<td><%= item.amount %></td>
</tr>
<tr>
<td colspan="3" align="left"><strong>TOTAL:</strong></td>
<td colspan="1"><%= item.amount %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="row">
<div class="span3">
<table>
<tbody>
<tr>
<td> <b>For Landlord</b></td></tr>
<tr> <td>Approved by:</td></tr>
<tr> <td>Sign:</td></tr>
</tbody>
</table>
</div>
<div class="span3" style="position: relative; align:left; left:150px;">
<table>
<tbody>
<tr>
<td> <b>For Tenant</b></td></tr>
<tr> <td>Approved by:</td></tr>
<tr> <td>Sign:</td></tr>
</tbody>
</table>
</div>
</div>
<br/>
<br />
<div>
<small><strong>Terms and Conditions</strong></small>
<table>
<tbody>
<tr>
<td><%= Settings.invoice_terms%></td>
</tr>
</tbody>
</table>
</div>
<br />
<div class="form actions">
<p>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_invoice_path, :class => 'btn btn-primary' %>
</p>
</div>
</div>
</div>
In my application.html.erb, I have this for CSS
<%= stylesheet_link_tag "application", :media => "all" %>
More to that, my application file has a nav-bar element.
I am trying to print the Invoices/show.html.erb page by going to the print option in a browser, however, I do not want it to include the nav-bar element in my application.html.erb file and the edit button in invoices/show.html.
I am using Twitter bootstrap, how can i go about this?
Here's one solution I've thought of:
What you can do is, in your show view (or the application layout) add a predicate:
if params[:controller] == "invoice" && params[:action] == "show"
# do or show whatever you want
end
Or you could do add a different layout to your views/layouts folder. Then in your controllers/invoice_controller
def show
# ...
render layout: 'a_different_layout_for_invoices'
end

Resources