jjzjj

ruby-on-rails - Rails ActionController::UnknownFormat 错误与 respond_to

我在尝试使用ajax时遇到此错误。我做了一些搜索,但无法解决我的问题ActionController::UnknownFormat草稿Controller:defindexifparams["format"]!=nil@draft=Draft.find_by(id:params["format"].to_i)respond_todo|format|format.jsendend@draft=current_user.drafts.build@drafts=current_user.drafts.non_submitted@being_edited_drafts=current_user

ruby - 具有 respond_with destroy 操作的 Rails 嵌套资源

嵌套资源销毁操作的适当respond_with行是什么?我的路线:resources:vendorsdoresources:products,:except=>[:index]endProduct#destroy(注意@vendor和@product与before_filter一起找到,此处省略)defdestroy@product.destroyrespond_with@vendor,@productend根据我的功能测试,这是返回/vendors/X/products/X而不是/vendors/X我是否应该将其更改为仅responed_to@vendor?

ruby-on-rails - respond_with redirect with notice flash message 不起作用

我正在使用Rails3.0.7。在我的Controller中:defcreate@subscription=Subscription\.new_from_nested_attributes_parameters(params[:subscription])if@subscription.saveflash[:notice]='TheSubscriptionwassuccessfullycreated.'endrespond_with@subscriptionend在View中:尽管正确保存了对象,但不打印任何内容。您知道我应该如何解决这个问题吗? 最佳答案

ruby-on-rails - rspec 测试 respond_to 格式和 csv

我想在我的rspecController中测试top_users是否等于User.top_users。我如何访问format.csv?我需要这样的东西:it"formatcsv"doget:index,format::csv#expect(something)……end稍后想测试csv:文件格式是否正确,不保存/下载它。Controller:defindexrespond_todo|format|format.csvdotop_users=User.top_userssend_data(top_users.to_csv,filename:"top-users-#{Time.zone.t

Ruby 的 `respond_to?` 在定义之后不起作用?

我有一个模块定义了一个方法,如果它还没有被定义的话。ActiveRecord的属性就是这种情况,因为它们的getter和setter未定义为方法。moduleBdefcreate_say_hello_if_not_existsputsrespond_to?(:say_hello)define_method:say_hellodoputs'hello'endunlessrespond_to?(:say_hello)endendclassAdefsay_helloputs'hi'endputsrespond_to?(:say_hello,true)extendBcreate_say_hel

ruby - respond_to only format.js 用于所有 mime 类型

我有一个响应于format.js的Controller,但是,大多数请求假设旧的format.html仍然存在并抛出404异常。如何捕获Controller上的所有MIME请求并将它们仅重定向到format.js?这是当前的ControllerActiondefsearchrespond_todo|format|unless@search.nil?format.js{render:partial=>'/search/search_form',:status=>200}elseformat.js{render:partial=>'/search/not_exist',:status=>5

ruby-on-rails - Rails respond_with 没有输出剩余调用的状态

我正在尝试使用respond_with方法使用rails制作一个简单的restapi,但它不想输出任何类型的状态消息例如,我希望它不仅返回get调用的json,还返回ok状态。当发布或删除有效/失败时也是如此。一些教程建议使用额外的:status参数,但它们似乎根本不会影响输出。defindex@conns=Connection.allrespond_with(@conns,:status=>:ok)end这会返回与:status=>:ok不存在时完全相同的内容。有什么想法吗??谢谢! 最佳答案 :status=>:ok设置HTTP

ruby-on-rails - RSpec 错误 "undefined method ` respond_with'..."

我正在学习教程http://apionrails.icalialabs.com/book/chapter_three但是当我运行Controller测试时bundleexecrspecspec/controllers我得到了未定义的方法错误:Failures:Api::V1::UsersControllerGET#showFailure/Error:it{shouldrespond_with200}NoMethodError:undefinedmethod`respond_with'for##./spec/controllers/api/v1/users_controller_spec

javascript - rails 3.1 : The new way to use 'respond_to ... format.js' without the 'page' variable

我正在尝试将RubyonRails更新到3.1版本。我关注了UpgradingtoRails3.1截屏视频和所有内容似乎都有效,除了format.js{render(:update){|page|page.redirect_to@article}}在许多Controller中,我有如下代码:defcreate...respond_todo|format|format.js{render(:update){|page|page.redirect_to@article}}endend在上述所有情况下,当我尝试提交执行JS请求的相关表单时,出现以下错误:ActionView::Missing

ruby - respond_to 和 respond_to_missing 有何不同?

我对何时使用这些方法感到困惑。来自respond_to?文档:Returnstrueifobjrespondstothegivenmethod.Privatemethodsareincludedinthesearchonlyiftheoptionalsecondparameterevaluatestotrue.Ifthemethodisnotimplemented,asProcess.forkonWindows,File.lchmodonGNU/Linux,etc.,falseisreturned.Ifthemethodisnotdefined,respond_to_missing?m