-1

I took over someone else's Rails project and I have a question about HTTP requests.

It SEEMS that I should be able to pass parameters through HTTP requests, I'm just unsure how. For example: rake routes shows

PUT    /auction2s/:id(.:format)                      auction2s#update

Which seems to correspond to this function

# PUT /auction2s/1
  # PUT /auction2s/1.json
  def update
    @auction2 = Auction2.find(params[:id])
    print "Hello World"
    respond_to do |format|
      if @auction2.update_attributes(params[:auction2])
        format.html { redirect_to @auction2, notice: 'Auction2 was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @auction2.errors, status: :unprocessable_entity }
      end
    end
   end

But I can't figure out the URL I would need to pass to, for instance, change

id=18445&done=true

into that function.

Any thoughts? Is the function structured right? Do I just need to pass the request in a Ruby format, not through the browser or AJAX (which is what I'm trying)?

Tommy Nicholas
  • 1,133
  • 5
  • 20
  • 31
  • First of all, your `routes` file says that `PUT` req is set to the `auction1s` and the code you mentioned is about `auction2s` ? – Ye Lin Aung Aug 20 '13 at 02:57
  • 2
    @NeerajT is too nice. His edit probably saved you from losing all your rep: http://stackoverflow.com/help/whats-reputation (See #5 in the "You lose reputation when" section). Programming problems can be frustrating, but it's generally a good idea (read: to your advantage) to leave the frustration out of your questions. – Adi Inbar Aug 20 '13 at 03:02
  • My fault - I just wanted you guys to understand how lost I really am, so that there wouldn't be assumptions about how I structured things when I was building it. – Tommy Nicholas Aug 20 '13 at 03:25
  • 1
    Lost or not, you've assumed a responsibility and frustration isn't a good thing to let out. Remember, SO isn't an unknown backwater site. Lots of (potential) employers surf this place. You don't want to admit frustration here; remember, the Internet never forgets. I can still find my contributions from over 20 years ago. :-) – the Tin Man Aug 20 '13 at 03:36
  • 1
    Thanks for the advice! I think it's more important just not to vent frustration in general to those other than your close friends, that really isn't what I was trying to do. – Tommy Nicholas Aug 20 '13 at 03:40
  • The accepted answer here is exactly what I needed http://stackoverflow.com/questions/18326582/ruby-on-rails-put-http-request-what-url-to-post – Tommy Nicholas Aug 20 '13 at 04:28

1 Answers1

0

You should have a form for this action. Most likely in this location -> app/views/auction1s/edit.html.erb. It will be edit.html.haml if you are using haml template engine. The form will be rendered in the view and user input will be sent as parameters to this action on submit of the form.

usha
  • 28,973
  • 5
  • 72
  • 93
  • Yes sir - I have an edit form there, but what I want to do is render changes from another view - IE app/views which renders all the auction2s (sorry I had a 1s in there, that's another MVC structure). – Tommy Nicholas Aug 20 '13 at 03:26
  • Then you will have to render that view explicitly in your `edit` action. `render :template => "auction2s/ – usha Aug 20 '13 at 03:57
  • Right, but that would just render the template - I actually want to send the put request. For more context, this is a checkbox, and everytime the checkbox is clicked, I want to change this boolean for done to "true" or "false". – Tommy Nicholas Aug 20 '13 at 04:02
  • For example: http://localhost:3000/auction2s/18445?done=false returns the parameters id=18445 and done="false" but as a GET request, not a put request – Tommy Nicholas Aug 20 '13 at 04:15
  • http://stackoverflow.com/questions/18326582/ruby-on-rails-put-http-request-what-url-to-post – Tommy Nicholas Aug 20 '13 at 04:27