我正面临着一大堵幼虫路线,我似乎找不到解决方案
我在视图模板中有这个表单
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | Start Date: <input type="date" required name="starting_date" value="" placeholder="From" class="request-input request-date mb10"> End Date: <input type="date" required name="ending_date" value="" placeholder="To" class="request-input request-date mb10"> Quantity <input type="number" required name="quantity" value="" placeholder="Quantity" class="request-input mb10"> Voltage <input type="number" required name="voltage" value="" placeholder="Voltage" class="request-input mb10"> Param 1 <input type="text" required name="param_1" value="" placeholder="Parameter" class="request-input mb10"> Param 2 <input type="text" required name="param_2" value="" placeholder="Parameter" class="request-input mb10"> <button class="btn btn-block button-orange">Get quotes now</button> </form> |
这是对应的路线
2 3 4 5 6 | Route::get('/my-requests/{readby_url}', 'PagesController@requests'); Route::post('/request/{equipment_url}', 'PagesController@request'); Route::post('/request/create', 'RequestsController@create'); Route::post('/request/accept', 'RequestsController@accept'); }); |
我的问题是
即它抛出错误
2 3 4 5 6 7 8 | in RouteCollection.php line 201 at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 188 at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 140 at RouteCollection->match(object(Request)) in Router.php line 746 at Router->findRoute(object(Request)) in Router.php line 655 at Router->dispatchToRoute(object(Request)) in Router.php line 631 at Router->dispatch(object(Request)) in Kernel.php line 237 |
我想同时传递一个参数和发布数据。
有没有办法让这个工作?有人告诉我 Route::post 也可以处理 GET,但它似乎不起作用。
问题与 Laravel 无关
将
您不能将获取参数发送到发布路由。
但是您可以通过一个简单的技巧来实现,只需在表单的隐藏字段或会话中传递您的值 ({{$equipment->url}})。
例如:
html
2 3 4 5 6 | {{Input::hidden('name-of-field', $equipment->url) ....... </form> |
路线
控制器
2 3 4 5 | { echo"[cc lang="php"]"; dd(Input::all()); } |
结果
2 3 4 | ["name-of-field"]=> string(5)"your value here" } |
HTTP POST 动词不接受来自 URL 的参数,如 GET,它接受来自 HTTP POST 正文的参数。要获取发布参数,请使用以下代码:
在 routes.php:
并在您的 PagesController 中使用以下输入方法之一访问表单输入
2 3 4 | { return Input::get('equipment_url'); } |
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
从给定URL下载文件并立即将其上传到AmazonS3的更直接的方法是什么(+将有关文件的一些信息保存到数据库中,例如名称、大小等)?现在,我既不使用Paperclip,也不使用Carrierwave。谢谢 最佳答案 简单明了:require'open-uri'require's3'amazon=S3::Service.new(access_key_id:'KEY',secret_access_key:'KEY')bucket=amazon.buckets.find('image_storage')url='http://www.ex
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
两者都可以defsetup(options={})options.reverse_merge:size=>25,:velocity=>10end和defsetup(options={}){:size=>25,:velocity=>10}.merge(options)end在方法的参数中分配默认值。问题是:哪个更好?您更愿意使用哪一个?在性能、代码可读性或其他方面有什么不同吗?编辑:我无意中添加了bang(!)...并不是要询问nobang方法与bang方法之间的区别 最佳答案 我倾向于使用reverse_merge方法:option
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use