John Stegman

Joined

180 Experience
0 Lessons Completed
0 Questions Solved

Activity

I am transferring an MS Access db to Rails and I need to be able to have a drop down list of customers (last_name, first_name, id) that will allow me to select a customer and generate the customer show page. I've been able to make the drop down but I can't figure out how to create the link to the show page

<%= @customers.each do |customer| %>

Posted in Processing by EquipmentController#show as */*

I'm getting this response when I send a jquery get request to render the show page for a piece of equipment - or any other show page for any object in the rails app for that matter (customer, warranty, etc)

I am using a select_tag to find the id of the item in question

<%= select_tag( "equip_id", options_from_collection_for_select(@equipment, :id, :equip_id, (@equipment_id.nil?) ? nil : @equipment_id), {:class => 'equipTag'}) %>

and am seeing that the app is getting the proper id - using alert - see the code below. However, when the server responds to the request, I get
Processing by EquipmentController#show as */* **
instead of
**Processing by EquipmentController#show as HTML

which I receive if I use a link to show in a table lising of the equipment items or enter the id manually in the browser address bar - /equipment/4567 for example

javascript code -

$(document).on('change', '.equipTag', function(){

    var equipId = $(this).val();
    alert (equipId);
    $.get('/equipment/' + equipId);

});

I'd appreciate any help. Thanks in advance.
John

Posted in Use select_tag to link to customer show page

I'd like it to render HTML, just like the rendering I receive when I input the user id in the browser adress bar.
As I tried to show above, I am having two problems:

  1. Can't seen to pass the custId to the url in the jquery line - get the error that the server couldn't find the customer - ActiveRecord::RecordNotFound (Couldn't find Customer with 'id'=custId):
    jquery code is

    $(document).ready
    $(document).on('change', '.custTag', function(){
    
    var custId = $(this).val();
    alert (custId);
    $.get('/customers/custId');
    

});


3. 2. When I input the customer id into the code directly, I get a mesage from the server - "Processing by CustomersController#show as  */*"  instead of the usual "Processing by CustomersController#show as HTML"

Posted in Use select_tag to link to customer show page

Thanks, Tabish - that is very helpful. I have studeied you code and it allowed me to understnd the need for a javascript portion to be added to the index page. Following is what I have done:

Set up a select_tag


<%= select_tag( "cust_id", options_from_collection_for_select(@customers.by_last_name, :id, :last_name, (@customers_id.nil?) ? nil : @customers_id), {:class => 'custTag'}) %> 

Set up a javascript on change listener for the select tag dropdown

$(document).ready
$(document).on('change', '.custTag', function(){
    var custId = $(this).val();
    alert (custId);
    $.get('/customers/custId');

});

Selecting a line in the dropdown gives the alert with the proper id for the line selected but causes the following server response:

Started GET "/customers/custId" for 73.183.17.149 at 2017-06-07 20:46:13 +0000
Processing by CustomersController#show as /
Parameters: {"id"=>"custId"}
Customer Load (0.6ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = $1 LIMIT $2 [["id", 0], ["LIMIT", 1]]
Completed 404 Not Found in 4ms (ActiveRecord: 0.6ms)

ActiveRecord::RecordNotFound (Couldn't find Customer with 'id'=custId):

Trying the direct method – entering a customer id into javascript

$(document).ready
$(document).on('change', '.custTag', function(){
var custId = $(this).val();
alert (custId)
$.get('/customers/6559');
});

I get the following server response – note the line Processing by CustomersController#show as */*

Started GET "/customers/6559" for 73.183.17.149 at 2017-06-07 20:34:21 +0000
Processing by CustomersController#show as /
Parameters: {"id"=>"6559"}
Customer Load (0.9ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = $1 LIMIT $2 [["id", 6559], ["LIMIT", 1]]
Equipment Load (12.6ms) SELECT "equipment".* FROM "equipment" WHERE "equipment"."customer_id" = 6559
Rendering customers/show.html.erb within layouts/application
Rendered collection of equipment/_equipment.html.erb 4 times
Rendered customers/show.html.erb within layouts/application (18.4ms)
Completed 200 OK in 655ms (Views: 628.3ms | ActiveRecord: 13.5ms)

However, nothing is rendered in the browser

Entering the customer id directly in the browser address bar (customers/6559) produces the desired result

Started GET "/customers/6559" for 73.183.17.149 at 2017-06-07 20:51:27 +0000
Processing by CustomersController#show as HTML
Parameters: {"id"=>"6559"}
Customer Load (0.9ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = $1 LIMIT $2 [["id", 6559], ["LIMIT", 1]]
Equipment Load (0.8ms) SELECT "equipment".* FROM "equipment" WHERE "equipment"."customer_id" = 6559
Rendering customers/show.html.erb within layouts/application
Rendered collection of equipment/_equipment.html.erb 4 times
Rendered customers/show.html.erb within layouts/application (5.7ms)
Completed 200 OK in 616ms (Views: 606.1ms | ActiveRecord: 1.7ms)

My goal is to click on the line in the select dropdown, pass the custId to the controller show action and have the page be rendered.

Am I making any progress?

Thanks for any help you can give

Posted in Use select_tag to link to customer show page

Sorry - relatively new to this process.
I assume you are suggesting some javascript code but am not too familar with the process I need to implement.

I'd appreciate any help you can provide.

Posted in Use select_tag to link to customer show page

I'm converting a MS access databse to Rails. The database has a customer table of over 5,000 customers. I have imprted the customer table from the Acces db into the Rails postgres db.

I can use the index view to see the customer list and access the show, edit or delete options - code below.

To replace the table in the index view, I've created a dropdown list that will list the customers alphabetically by last name and allow the user to select the customer. I am unable however to get the app to perform the action I want - render the customer show page.

How does one get a dropdown box to intiate the rendering of the show page for the selected customer?

My code so far for the customer index page. I left the table portion in but obviously that's what I want the dropdown box to replace.

<p id="notice"><%= notice %></p>

<h1>Customers</h1>
<%= select_tag 'cust_id', options_for_select(@customers.by_last_name.collect{ |c| [c.last_name, c.first_name, c.id]}) %>

<table>
  <thead>
    <tr>
      <th>ID</th>
      <th>First name</th>
      <th>Last name</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @customers.each do |customer| %>
      <tr>
        <td><%= customer.id %></td>
        <td><%= customer.first_name %></td>
        <td><%= customer.last_name %></td>
        <td><%= link_to 'Show', customer %></td>
        <td><%= link_to 'Edit', edit_customer_path(customer) %></td>
        <td><%= link_to 'Destroy', customer, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<%= link_to 'New Customer', new_customer_path %>