首页 \ 问答 \ Ruby on Rails - Rspec - 控制器测试 - 嵌套路由(Ruby on Rails - Rspec - Controller test - nested route)

Ruby on Rails - Rspec - 控制器测试 - 嵌套路由(Ruby on Rails - Rspec - Controller test - nested route)

我有一个非常基本的控制器测试

require 'spec_helper'

describe Admin::OrdersController do 

    describe "GET #order_detail" do 
        before :each do 
            new_admin = FactoryGirl.create(:admin)
            sign_in new_admin
            @storefront = FactoryGirl.create(:storefront)
            @order = FactoryGirl.create(:order)

         end

         it "assigns the requested order to @order" do
             get :order_detail, { :storefront_id => @storefront.id, :order_id => @order.id }
             assigns(:order).should eq(@order)
         end

         it "renders the :show template" do
             get :order_detail, {:storefront_id => @storefront.id, :order_id => @order.id}
             response.should render_template :order_detail
         end
    end 
end

这两个操作都会出现以下错误:

ActionController::RoutingError:
    No route matches {:storefront_id=>"14", :order_id=>"1", :controller=>"admin/orders", :action=>"order_detail"}

来自routes.rb:

resources :storefronts do
  resources :orders do
    member do
      get :order_detail
    end
  end
end

我想

get :order_detail, { :storefront_id => @storefront.id, :order_id => @order.id }

将是生成路线的正确方法,但不幸的是,它不是。


I got a pretty basic controller test

require 'spec_helper'

describe Admin::OrdersController do 

    describe "GET #order_detail" do 
        before :each do 
            new_admin = FactoryGirl.create(:admin)
            sign_in new_admin
            @storefront = FactoryGirl.create(:storefront)
            @order = FactoryGirl.create(:order)

         end

         it "assigns the requested order to @order" do
             get :order_detail, { :storefront_id => @storefront.id, :order_id => @order.id }
             assigns(:order).should eq(@order)
         end

         it "renders the :show template" do
             get :order_detail, {:storefront_id => @storefront.id, :order_id => @order.id}
             response.should render_template :order_detail
         end
    end 
end

Which gets me the following error for both actions:

ActionController::RoutingError:
    No route matches {:storefront_id=>"14", :order_id=>"1", :controller=>"admin/orders", :action=>"order_detail"}

From the routes.rb:

resources :storefronts do
  resources :orders do
    member do
      get :order_detail
    end
  end
end

I thought

get :order_detail, { :storefront_id => @storefront.id, :order_id => @order.id }

would be the right way to generate the route but unfortunately it's not.


原文:https://stackoverflow.com/questions/22467434
更新时间:2023-09-03 12:09

最满意答案

在第一个Child-Cell的边缘使用.animate()方法。

“细胞”类由200x200个盒子组成,全部向左浮动。 ID“容器”也是200x200,隐藏溢出。 您可以指定三个链接来动画第一个具有“单元格”类的div的左边距,这将根据您想要的数量向左或向右移动所有三个。

Link1 - > First Div Margin Left = 0;
Link2 - > First Div Margin Left = -200;
Link3 - > First Div Margin Left = - 400;


更新:以下代码已更新,以回应评论中的后续问题。

我已将细胞封入另一个div中。 这个div在容器内。 我们不是操纵第一个单元格的左边距,而是操纵这些单元格所在的div的左边距。 给这一点 - 我已经尝试过并获得了预期的结果。

<style type="text/css">
  div#container { width:200px;height:200px;overflow:hidden; }
  div.cells { width:600px;height:200px;}
  div.cell { float:left;width:200px;height:200px;margin:0;padding:0; }
  div.cell p {margin:0;padding:0;}
</style>

<ul>
  <li><a href="#" class="box-mover">Show Box 1</a></li>
  <li><a href="#" class="box-mover">Show Box 2</a></li>
  <li><a href="#" class="box-mover">Show Box 3</a></li>
</ul>

<div id="container">
  <div class="cells">
    <div class="cell" style="background:#f1f1f1;">
      <p>Cell 1</p>
    </div>
    <div class="cell" style="background:#cc0000;color:#ffffff;">
      <p>Cell 2</p>
    </div>
    <div class="cell" style="background:#f1f1f1;">
      <p>Cell 3</p>
    </div>
  </div>
</div>

<script type="text/javascript">
  $(document).ready(function(){

    $("a.box-mover:eq(0)").click(function(event){
      event.preventDefault();
      $("div.cells").animate({"marginLeft": "0px"}, "slow");
    });
    $("a.box-mover:eq(1)").click(function(event){
      event.preventDefault();
      $("div.cells").animate({"marginLeft": "-200px"}, "slow");
    });
    $("a.box-mover:eq(2)").click(function(event){
      event.preventDefault();
      $("div.cells").animate({"marginLeft": "-400px"}, "slow");
    });

  });
</script>

Use the .animate() method on the margins of the first Child-Cell.

Class "cell" consists of 200x200 boxes, all floated left. ID "container" is also 200x200, with an overflow of hidden. You could assign three links to animate the margin-left of the first div having the class "cell," which would move all three left or right, depending on the amount you want.

Link1 -> First Div Margin Left = 0;
Link2 -> First Div Margin Left = -200;
Link3 -> First Div Margin Left = - 400;


Update: The following code has been updated in response to follow up questions within the comments.

I've enclosed the cells within another div. This div is within the container. Rather than manipulating the left-margin of the first cell, we're going to manipulate the left-margin of the div that these cells reside within. Give this a shot - I've tried it and Got the desired results.

<style type="text/css">
  div#container { width:200px;height:200px;overflow:hidden; }
  div.cells { width:600px;height:200px;}
  div.cell { float:left;width:200px;height:200px;margin:0;padding:0; }
  div.cell p {margin:0;padding:0;}
</style>

<ul>
  <li><a href="#" class="box-mover">Show Box 1</a></li>
  <li><a href="#" class="box-mover">Show Box 2</a></li>
  <li><a href="#" class="box-mover">Show Box 3</a></li>
</ul>

<div id="container">
  <div class="cells">
    <div class="cell" style="background:#f1f1f1;">
      <p>Cell 1</p>
    </div>
    <div class="cell" style="background:#cc0000;color:#ffffff;">
      <p>Cell 2</p>
    </div>
    <div class="cell" style="background:#f1f1f1;">
      <p>Cell 3</p>
    </div>
  </div>
</div>

<script type="text/javascript">
  $(document).ready(function(){

    $("a.box-mover:eq(0)").click(function(event){
      event.preventDefault();
      $("div.cells").animate({"marginLeft": "0px"}, "slow");
    });
    $("a.box-mover:eq(1)").click(function(event){
      event.preventDefault();
      $("div.cells").animate({"marginLeft": "-200px"}, "slow");
    });
    $("a.box-mover:eq(2)").click(function(event){
      event.preventDefault();
      $("div.cells").animate({"marginLeft": "-400px"}, "slow");
    });

  });
</script>

相关问答

更多
  • 您可以使用内置SmartLinkLabel的 Wicket。 从Javadoc: 如果您显示的数据中包含电子邮件地址或网址,则可以自动将这些数据显示为超链接,您不必采取任何操作即可转换该数据。 You can use Wicket's built in SmartLinkLabel. From the Javadoc: If you have email addresses or web URLs in the data that you are displaying, then you can autom ...
  • 我想我找到了一个解决方案,但是,我不太喜欢它。 为每个未链接的元素添加“onclick”属性(无论是否为空)使其在Firefox浏览器中可触摸。 这可以通过一个小的JavaScript循环来实现。 更好的解决方案表示赞 I think I've found a solution, however, I don't like it very much. Adding an "onclick" attribute (whether empty or not) to each unlinked element m ...
  • SlidingDrawer只能从右侧或底部滑入,无法从顶部或左侧滑入。 你可以尝试从这个问题的答案: 从顶部的Android SlidingDrawer? 或者你可以尝试重写源代码http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/SlidingDrawer.java 。 但是,SlidingDrawer不会允许 白色面板显示所有内容,不在任何面板 ...
  • 在第一个Child-Cell的边缘使用.animate()方法。 “细胞”类由200x200个盒子组成,全部向左浮动。 ID“容器”也是200x200,隐藏溢出。 您可以指定三个链接来动画第一个具有“单元格”类的div的左边距,这将根据您想要的数量向左或向右移动所有三个。 Link1 - > First Div Margin Left = 0; Link2 - > First Div Margin Left = -200; Link3 - > First Div Margin Left = - 400; 更 ...
  • 将内容插入面板时,选项卡是页面元素组的一部分。 您可以在底部右侧列中看到标签。 如果将其添加到面板,则会在节点页面上显示选项卡。 Tabs are a part of the page elements group when inserting content into your panels. You can see the tabs in the right column at the bottom. If you add that to your panel then you will get the ...
  • 不确定你在寻找什么,但也许就是这样: http : //jsfiddle.net/adeneo/fE8ks/4/ Not sure what your looking for, but maybe this is it : http://jsfiddle.net/adeneo/fE8ks/4/
  • 你真的需要在左边放置带边距的元素吗? 因为如果它可以让你简单地隐藏它们,那么实现你效果的代码非常简单: $(document).ready(function() { $('#container').css({position:'relative'}); $("#container div:not(:first)").hide(); $('.div1').addClass('current'); $("nav a").click(function() { var cls ...
  • 我喜欢http://www.davidmassiani.com/horinaja/ 它可以使用鼠标滚轮以及在窗格之间滚动的链接,它可用于script.aculo.us和jQuery。 我推荐后者,因为它重量轻,易于学习/处理。 I like http://www.davidmassiani.com/horinaja/ It can use the mousewheel aswell as the links to scroll between panes, and it's available for sc ...
  • 您所要做的就是在执行滑入动画之前重置定位。 $('.navigation a').click(function(e) { e.preventDefault(); var prevPanel = $('.navigation a.active').attr('data-panel'); var currPanel = $(this).attr('data-panel'); $('.panel').removeClass('active'); if (currPanel > ...
  • 这不是您正在寻找的,也不是与您发布的代码有关。 但是,我把一些东西扔在一起,这可能是你看的好资源。 它没有实现堆栈,但您可以非常轻松地应用这些概念。 看看吧 。 您可以摆脱createPanel函数并在init函数中预先创建/分配所有面板,然后让控制器使用这些面板作为基础。 然后,这只是控制在DOM中显示的内容的问题 display: none 将有效地从DOM中删除元素记住,并可用于隐藏某些面板。 This isn't exactly what you're looking for, nor is it ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)