- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Rails Controller 中从使用 respond_to 切换到 respond_with。一切都很顺利,除了测试 Controller 规范中的无效保存。下面是一个例子:
描述 MyController 做
...
describe "PUT update" do
context "with invalid attributes" do
it "should re-render the edit page" do
style = stub_model(Style)
Style.stub(:find) { style }
Style.any_instance.stub(:save).and_return(false)
put :update
response.should render_template(:edit)
end
end
end
end
Failure/Error: response.should render_template("edit")
def update
@style = Style.find(params[:id])
flash[:notice] = "Style updated" if @style.update_attributes(params[:style])
respond_with(@style)
end
最佳答案
我一直在研究这个确切的事情(我是如何找到这个话题的) - 到目前为止,我有以下几点:
Location.any_instance.stub(:valid?).and_return(false)
Location.any_instance.stub(:errors).and_return('anything')
关于ruby-on-rails - Rails respond_with & Rspec Controller : Testing unsuccessful update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10215156/
来自 rails 4.2 , respond_with和非实例级别 respond_to已移至responders gem 。如果我想写一个 json 响应所以我不需要 responders gem
我正在阅读 Rails 3 in Action 中的第 13 章,我在 respond_with 方法中使用哈希 :methods => "last_ticket"。但是我不明白这是做什么的,也不知道
我正在 Rails 3.1 中构建一个简单的 json API。我创建了一个具有两个功能的 Controller : class Api::DogsController "success"})
我有一个在 ruby v.1.9.3 上运行的 Rails 3 应用程序,具有用户、帖子和角色模型。一个用户拥有多个帖子和角色。 我的routes.rb 文件如下所示: namespace :ap
我有一个在 ruby v.1.9.3 上运行的 Rails 3 应用程序,带有用户、帖子 和角色 模型。一个用户有很多帖子和角色。 我的 routes.rb 文件是这样的: namespace :
尝试在 Rails Controller 中使用返回时遇到问题。这不起作用: class UsersController ): app/controllers/users_controller.rb:
我正在尝试使用 respond_with 方法使用 rails 制作一个简单的 rest api,但它不想输出任何类型的状态消息 例如,我希望它不仅返回 get 调用的 json,还返回 ok 状态。
我试图在 respond_to JSON 散列中包含一个虚拟属性/方法。 模型 (employee.rb) attr_reader :my_method def my_method return
我有一个简单的模型: class Receipt include ActiveModel::Serialization attr_accessor :products end 我的 Contr
我正在尝试在 Rails 中提供自定义 404 响应,但我不确定如何将 :status 赋予 respond_with 函数。 我知道使用 render,我可以这样做: render :status
我的一个 Controller 中有以下内容: def create photo.user = current_user if current_user flash[:notice] = "T
在我的项目中我有 respond_to :json load_and_authorize_resource def show respond_with @job_pattern end 按照这里的
我正在寻找一种方法来缩短生成 json 的 respond_with 中的 :include => :child。 这是一个例子,不确定是否可行,但我想知道。 在 Controller 中: @p =
在为提供 json 的 Rails 3.0.3 应用构建 API 时,发生了一些意外行为。 以下是 Controller 。问题是关于 respond_with。我已经在应用程序 Controller
生成一些 json 时遇到问题。我正在尝试渲染像这样的 json 的单个事件记录结果: @data = User.find(1) respond_with(@data, :include => :st
在 Controller 中,我想替换 if..render..else..render与 respond_with : # Current implementation (unwanted) def
respond_to有什么区别和 respond_with ? 他们在做什么? 任何人都可以发布带有输出屏幕截图的示例吗? 谢谢。 最佳答案 有一个非常完整的答案here .本质上 response_
为什么在这种情况下respond_with不响应json?我使用显式 .json (/tasks/4e3c1163a19d461203000106/items/4e4c27dfa19d46e0e400
提前为这个问题的冗长道歉。如果您耐心等待我,我想您会发现它实际上非常简单……鉴于我有限的 Rails 领域知识,我很难解释清楚。 鉴于 an ActionController commit dated
我创建了一个用 json 响应的简单 api。当我尝试从浏览器调用它时,我得到了适当的 json 响应,但是当我尝试从 actionscript 远程调用它时,它似乎试图调用 json,就好像它是一个
我是一名优秀的程序员,十分优秀!