简体   繁体   English

无法从 Controller 呈现页面以在 Rails 中查看

[英]Not able to render page from Controller to view in Rails

I am getting 404 This page is missing.我收到 404 此页面丢失。 I need to pass controller results to view.I have added respective controller and views.I am getting values in controller but not passing those values to views.I didn't get any errors as well.Can anyone help on this?我需要将 controller 结果传递给查看。我已经添加了相应的 controller 和视图。我在 controller 中获取值,但没有将这些值传递给视图。

Below the code I am trying在我正在尝试的代码下方

Controller Controller

class CompareResultsController < ApplicationController

    def compare_results

        executionId1=params['executionId1']
        executionId2=params['executionId2']
         @execution_results1 = ExecutionResult.where(:execution_id => executionId1).pluck(:parametersname,:actual_value)
    
         @execution_results2 = ExecutionResult.where(:execution_id => executionId2).pluck(:parametersname,:actual_value)
    
         puts @execution_results1
    
         puts @execution_results2
    
   
     end

     
    end

JS Code JS代码

function compareExecutionResults() {
    
        var checkBoxValue=[]
        $("input[type='checkbox']:checked").each(function(){
            checkBoxValue.push($(this).val());
        });
        var executionId1=checkBoxValue[0];
        var executionId2=checkBoxValue[1];
        
          $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/compare_results/compare_results",
            data: JSON.stringify({
                executionId1: executionId1,
                executionId2: executionId2
                 }),
               success: function (result) {
              if (result === 'false') {
                  alert('Description  not Updated  !!!');
                  return false;
               } else {
                  alert('Comparing Values !!!');
                  window.location.href = "/compare_results/compare_results";

                }
              }
           }); 
         }

routes路线

  post "/compare_results/compare_results", to: "compare_results#compare_results"

HTML: HTML:

<table>
  <tr>
    <th>Sr.no</th>
    <th>Param Name</th>
    <th>Value</th>
    <th>Param Name</th>
    <th>Value</th>
    <th>Matched</th>
  </tr>
  <% @execution_results.each do |result, index| %>
    <tr>
      <td><%= index + 1 %></td>
      <td><%= result.name %></td>
      <td><%= result.value %></td>
      <td><%= @execution_results2[index].name %></td>
      <td><%= @execution_results2[index].value %></td>
      <td><%= compare_function(result, @execution_results2[index]) %></td>
    </tr>
  <% end %>
</table>

Html View Html 查看

Views--compare_results--compare_results.html.erb file

You need to make sure that the compare_results method of the controller is exposed in the config/routes.rb file as it is not a standard resource.您需要确保 controller 的compare_results方法在config/routes.rb文件中公开,因为它不是标准资源。

Sth like this might help:像这样的东西可能会有所帮助:

post '/compare_results/compare_results', to: 'compare_results#compare_results'

Most probably you are not giving correct path, to check if this is the problem run the following command in terminal, if your rails version is greater than 5 then rails routes , or if its less than 5 then rake routes .很可能您没有提供正确的路径,以检查这是否是问题在终端中运行以下命令,如果您的 rails 版本大于 5 则rails routes ,或者如果其小于 5 则rake routes

By doing this you will be able to see what URL are being served by your app.通过这样做,您将能够看到您的应用程序正在为 URL 提供哪些服务。 Now check if there is a URL(path) matching with the controller action.现在检查是否有与 controller 操作匹配的 URL(路径)。 After that make sure that you have used correct path.之后确保您使用了正确的路径。

Note: By path I mean which you may have given in link_to to visit this page.注意:我所说的路径是指您可能在 link_to 中给出的访问此页面的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM