我可以使用没有数据库的资源路由(没有ids) [英] Can I use resource routes without a database (without ids)

查看:173
本文介绍了我可以使用没有数据库的资源路由(没有ids)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个没有模型,没有数据库的UI应用程序。它对其所有的业务逻辑使用Web服务调用。我有一个令人难以置信的困难的时间得到路由完成。我还有像工作站的实体。我已经在我的路由 resource:workstations 中声明了这些路由:

I'm building an UI app that has no models, no database. It uses web-service calls for all of its business logic. I'm having an unbelievably difficult time getting the routing complete. I still have entities like workstations. I've declared in my routes resource :workstations which gives me these routes:

     workstations POST   /workstations(.:format)      workstations#create
 new_workstations GET    /workstations/new(.:format)  workstations#new
edit_workstations GET    /workstations/edit(.:format) workstations#edit
                  GET    /workstations(.:format)      workstations#show
                  PUT    /workstations(.:format)      workstations#update
                  DELETE /workstations(.:format)      workstations#destroy

但是当我尝试链接到更新操作, code> = link_toUpdate,workstations_path,:method => :put 我得到没有路由匹配{:controller =>workstations,:method =>put} 。是不是列出的更新操作的路由?

but when I try to link to an update action like = link_to "Update", workstations_path, :method => :put I get No route matches {:controller=>"workstations", :method=>"put"}. Isn't that the route thats listed for the update action?

我想知道,如果我不能使用传统的资源路由,因为我没有 ids

I'm wondering if I can't use traditional resourceful routes since I don't have ids. Or maybe I'm just doing it wrong.

查看代码(Haml):

View code (Haml):

%h2
  %small#application-name-label Technical Support Interface
.col-md-3
  %h3 Workstations
  %button.btn.btn-success.create-button Create Workstation
  - if @workstations.blank?
    .no-items-available There are no workstations to display
  -else
    = form_tag(controller: "workstations", action: "delete_history_and_queue", method: "post") do
      %table#workstation-table.table.table-striped.table-hover.table-bordered
        %thead
          %tr
            %th#table-header Name
            %th#table-header Delete History
            %th#table-header Delete Queue
            %th#table-header Update
            %th#table-header Delete
        %tbody
          - @workstations.each do |workstation|
            %tr
              %td
                = workstation[:name]
              %td
                = check_box_tag 'delete history', form_class: "checkbox"
              %td
                = check_box_tag 'delete queue', form_class: "checkbox"
              %td
                = link_to "Update", workstations_path, :action => :update
              %td
                = link_to "Delete", workstations_path, :action => :destroy
    = submit_tag
.col-md-3
  %h3 Data Sources
  %button.btn.btn-success.create-button Create Data Source
  - if @data_sources.blank?
    .no-items-available There are no sources to display
  -else
    %table.table.table-striped.table-hover.table-bordered
      %tr
        %th#table-header Type
        %th#table-header Name
      - @data_sources.each do |data_source|
        %tr
          %td
            = data_source[:type]
          %td
            = data_source[:name]

HTML

<body>
    <div class='whole-page'>
      <div class='container'>
        <h1 class='hero-unit' id='application-title'>
          <div class='row-fluid'>
            <div class='span1' id='replication-server'>
              <img alt="Cog_logo" src="/assets/cog_logo.png" />
              <img alt="Crs" src="/assets/crs.png" />
              Replication Server
            </div>
          </div>
        </h1>
      </div>
    </div>
    <h2>
      <small id='application-name-label'>Technical Support Interface</small>
    </h2>
    <div class='col-md-3'>
      <h3>Workstations</h3>
      <button class='btn btn-success create-button'>Create Workstation</button>
      <form accept-charset="UTF-8" action="/?method=post" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="NQghiooSVtSngRU7K170uxhqJ2N6i9XQ6sP5W+UeKrY=" /></div>
        <table class='table table-striped table-hover table-bordered' id='workstation-table'>
          <thead>
            <tr>
              <th id='table-header'>Name</th>
              <th id='table-header'>Delete History</th>
              <th id='table-header'>Delete Queue</th>
              <th id='table-header'>Update</th>
              <th id='table-header'>Delete</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                consequatur
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
            <tr>
              <td>
                quia
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
            <tr>
              <td>
                quod
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
            <tr>
              <td>
                reprehenderit
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
            <tr>
              <td>
                laborum
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
            <tr>
              <td>
                quidem
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
            <tr>
              <td>
                laboriosam
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
            <tr>
              <td>
                non
              </td>
              <td>
                <input id="delete_history" name="delete history" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <input id="delete_queue" name="delete queue" type="checkbox" value="{:form_class=&gt;&quot;checkbox&quot;}" />
              </td>
              <td>
                <a href="/workstations" action="update">Update</a>
              </td>
              <td>
                <a href="/workstations" action="destroy">Delete</a>
              </td>
            </tr>
          </tbody>
        </table>
      </form>
      <input name="commit" type="submit" value="Save changes" />
    </div>
    <div class='col-md-3'>
      <h3>Data Sources</h3>
      <button class='btn btn-success create-button'>Create Data Source</button>
      <table class='table table-striped table-hover table-bordered'>
        <tr>
          <th id='table-header'>Type</th>
          <th id='table-header'>Name</th>
        </tr>
        <tr>
          <td>
            CIDNE
          </td>
          <td>
            http://block.com/keaton_baumbach
          </td>
        </tr>
        <tr>
          <td>
            DCGS
          </td>
          <td>
            http://wolff.info/jace_rice
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>


推荐答案

或ids。

如果你使用 rails s ,您可能想重新启动,我在过去的路由问题是重新开始修复。

If you're testing using rails s, you may want to re-start, I've had routing issues in the past that a re-start fixed.

这篇关于我可以使用没有数据库的资源路由(没有ids)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆