jjzjj

SetDefaultValueFor_my_parameter

全部标签

ruby-on-rails - cucumber + capybara : Problem with a scenario that redirects the browser outside of my app

GivenIhavearailsappAndI'musingcucumberAndI'musingcapybaraAndIhaveanactionthatresultsinaredirect_to"http://some.other.domain.com/some_path"WhenItestthisactionThenthein-appportionofthetestworksfineButIseethiserror:Noroutematches"/some_path"with{:method=>:get}(ActionController::RoutingError)所以capyb

ruby-on-rails - 摩卡 : How to add expectation of a method when there are multiple invocations with different parameters

我有一个RailsControllerAction要测试。在那个Action中,一个方法User.can?使用不同的参数多次调用。在其中一个测试用例中,我想确保User.can?('withdraw')被调用。但我不关心User.can的调用?与其他参数。defaction_to_be_tested...@user.can?('withdraw')...@user.can?('deposit')...end我在测试中尝试了以下:User.any_instance.expects(:can?).with('withdraw').at_least_once.returns(true)但是测

ruby-on-rails - rails : Unpermitted parameter in Rails 5

首先,我只想在发送到我的后端的当前对象中获取一个对象。我有这个简单的JSON(从表单生成):{"name":"Project1","project_criteria":[{"name":"Criterium1","type":"Type1","benefit":"1"},{"name":"Criterium2","type":"Type2","benefit":"3"}]}我的类(class):classProject项目Controller:defproject_paramsparams.require(:project).permit(:name,project_criteria:

ruby-on-rails - rails : Why images are not showing in my rails basic app

我的index.html.erb代码-Listingproducts'list_image')%>图像在app\assets\images下..但是前端没有显示静态图像。当我Firebug它时,我相信图像标签是正确形成的...让我知道我在这部分缺少什么。截图-图片也到位了-让我知道我做错了什么,我该如何解决。编辑github.com/swapnesh/depot请告诉我为什么它在我的案例中不起作用。尽管更改/images/product1.jpgTo/assets/product1.jpg使其正常工作。 最佳答案 如果您正在使用As

ruby-on-rails - 我如何解决 "Missing host to link to! Please provide the :host parameter"? (返回率)

我正在关注RoRTutorial我被困在Listing9.15运行'bundleexecrspecspec/'后出现以下错误:1)AuthenticationauthorizationaswrongusersubmittingaPATCHrequesttotheUsers#updateactionFailure/Error:specify{expect(response).toredirect_to(root_url)}ArgumentError:Missinghosttolinkto!Pleaseprovidethe:hostparameter,setdefault_url_opti

ruby - RSpec stub : Return the parameter

虽然我的问题很简单,但我没能在这里找到答案:如何stub方法并返回参数本身(例如在执行数组操作的方法上)?像这样:interface.stub!(:get_trace).with().and_return() 最佳答案 注意:stub方法已被弃用。请看thisanswer以现代方式做到这一点。stub!可以接受一个block。block接收参数;block的返回值是stub的返回值:classInterfaceenddescribeInterfacedoit"shouldhaveastubthatreturnsitsargument

ruby - 轨道 3/ ruby : ActiveRecord Find method IN condition Array to Parameters single quote issue

我在微博模型上创建了一个方法,它接受一个user_id数组。在此方法中,我使用以下“查找”方法来提取数组中所有用户的所有帖子。find(:all,:conditions=>["user_idIN(?)",args.join(',')])但是当ActiveRecord为这个查询生成SQL时,它用单引号将逗号分隔的ID列表括起来。这会导致查询只提取单引号内第一个数字的帖子,而不是所有数字。SELECT`microposts`.*FROM`microposts`WHERE(user_idIN('3,4,5'))ORDERBYmicroposts.created_atDESC查询应该看起来像这

ruby-on-rails - Rails 4.0 Strong Parameters 嵌套属性带有指向散列的键

我在玩Rails4.xbeta并试图让嵌套属性与carrierwave一起工作。不确定我在做什么是正确的方向。四处搜索之后,最终查看了rails源代码和强大的参数,我发现了以下注释。#Notethatifyouuse+permit+inakeythatpointstoahash,#itwon'tallowallthehash.Youalsoneedtospecifywhich#attributesinsidethehashshouldbewhitelisted.https://github.com/rails/rails/blob/master/actionpack/lib/actio

ruby-on-rails - rails : URL/path with parameters

我想生成一个URL作为/swimming/students/get_times/2013-01-01/2013-02-02从这条路线get_class_swimming_studentsGET/swimming/students/get_times/:start_date/:end_date(.:format)swimming/students#get_times如何将参数传递给get_class_swimming_students_path? 最佳答案 get_class_swimming_students_path('2013-

ruby-on-rails - 更改 :id parameter in Routing resources for Rails 的名称

我四处查看如何更改动态参数槽,发现这篇文章完全符合要求。帖子是https://thoughtbot.com/blog/rails-patch-change-the-name-of-the-id-parameter-in基本上它所做的是,如果以下是路线:map.resources:clients,:key=>:client_namedo|client|client.resources:sites,:key=>:namedo|site|site.resources:articles,:key=>:titleendend这些路由创建以下路径:/clients/:client_name/cli