Tag: put

RSpec测试PUT更新动作

我正在尝试编写一些RSpec测试来测试我的应用程序,但我偶然发现了一些我找不到任何解决方案的问题。 1)我正在尝试测试更新操作。 这是我的代码: it “email is a new one” do put :update, id: @user, user: FactoryGirl.attributes_for(:user, :email=>”a@bc”) @user.reload @user.email.should == “a@bc” puts @user.email end 这是UsersController更新操作: def update @user = User.find(params[:id]) respond_to do |format| if @user.update_attributes(params[:user]) format.html { redirect_to edit_user_path(@user), :notice => “Your settings were successfully updated.”} format.json { head :no_content } else format.html { render […]

Rails Put vs Post

我一直在阅读put和post请求之间的区别,我有一些与rails相关的问题:我想更改已经创建的行中的一个特定字段…我应该使用put还是post请求? 例如以下不同? #Assume this is a put request def update @model=Model.find(x) @model.field=”new_field” @model.save end #Assume this is a post request def update @model=Model.find(x) @model.field=”new_field” @model.save end #What if I use the rails update method? def update @model=Model.find(x) @model.update(model_params) @model.save end 提前致谢。

link_to更新(没有表格)

我想要一个更新资源的链接,而不使用HTML表单。 路线: resources :users do resource :profile, :controller=>”profiles” resources :friends end 耙路线: user_friend GET /users/:user_id/friends/:id(.:format){:action=>”show”, :controller=>”friends”} PUT /users/:user_id/friends/:id(.:format){:action=>”update”, :controller=>”friends”} 我想通过简单的链接使用put来更新朋友,如下所示: ‘put’)%> 但是当Rails遇到这个链接时,他试图进入节目动作。 问题是:这样做的正确链接是什么?

Ruby:PUT请求与JSON正文?

我需要使用ruby创建HTTP PUT请求 。 该请求具有JSON正文 我能够使用以下方法生成JSON主体: require ‘rubygems’ require ‘json’ jsonbody = JSON.generate[“message”=>”test”,”user”=>”user1″] 我需要将此PUT请求发送到url: require ‘open-uri’ url = URI.parse(‘http://www.data.com?access_token=123’) 有人可以告诉我如何在Ruby中做到这一点?