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
最满意答案
在第一个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 ...
-
Firefox mobile:通过触摸其他地方来激活链接(Firefox mobile: Links getting activated by touching elsewhere)[2023-02-15]
我想我找到了一个解决方案,但是,我不太喜欢它。 为每个未链接的元素添加“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 ... -
Android滑动面板(Android sliding panels)[2022-02-05]
SlidingDrawer只能从右侧或底部滑入,无法从顶部或左侧滑入。 你可以尝试从这个问题的答案: 从顶部的Android SlidingDrawer? 或者你可以尝试重写源代码http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/SlidingDrawer.java 。 但是,SlidingDrawer不会允许 白色面板显示所有内容,不在任何面板 ... -
由链接激活的滑动面板(Sliding Panels activated by Links)[2021-01-25]
在第一个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 ...
-
Jquery滑动面板(再次)(Jquery sliding panels (again))[2023-12-20]
不确定你在寻找什么,但也许就是这样: http : //jsfiddle.net/adeneo/fE8ks/4/ Not sure what your looking for, but maybe this is it : http://jsfiddle.net/adeneo/fE8ks/4/ -
Jquery滑动面板(Jquery sliding panels)[2021-01-24]
你真的需要在左边放置带边距的元素吗? 因为如果它可以让你简单地隐藏它们,那么实现你效果的代码非常简单: $(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 ...