0

I am attempting to use the PATCH/PUT actions on the method on controller:

def specialClickThrough
        # Incriment click
        clickIncrimentBudgetReduce = "UPDATE `campaigns` 
                                        SET clicks = clicks + 1
                                        , budget = (budget - bid_price)
                                        , is_active = CASE
                                                      WHEN (budget - bid_price) > 0.0
                                                        THEN 1
                                                      ELSE 0
                                                      END   
                                        WHERE id = " + params[:campaign_id].to_s  

        ActiveRecord::Base.connection.execute(clickIncrimentBudgetReduce)
    end

When typing: localhost:3000/specialClickThrough/27 into the browser it returns that: No route matches [GET] "/specialClickThrough/27", even though there clearly is one as:

match '/specialClickThrough/:campaign_id', to: 'requests#specialClickThrough', via: 'put'

UPDATE

I tried in the postman chrome extension but still nothing:

enter image description here

From the docs it notes to simply set the request type as the one required. How can I get this to work?

Sauron
  • 6,399
  • 14
  • 71
  • 136
  • Maybe, the route is correct. But, your HTTP request is wrong. Yout don't have `GET /specialClickThrough/:id` route. That's why `No route matches [GET] "/specialClickThrough/27"` returned. You should add `<%= link_to 'special click through`, special_click_through_path, method: :put %>` and click it. – shoji Jan 25 '15 at 01:02
  • Try to look at what routes are actually available. To do so, you can do `bin/rake routes` (rails 4) – Edward Jan 25 '15 at 03:55
  • @Edward When I pass the route, it does appear as being available, I just don't know how to properly call it. How do I properly call a PUT route, without using GET? – Sauron Jan 25 '15 at 04:01
  • @Sauron See my answer below – Edward Jan 25 '15 at 04:09

2 Answers2

0

If you add the via: 'put' option, the GET won't work... So, how are you trying to perform the PUT request? try using curl or postman maybe... The route is well defined. The problem is you are doing a GET instead a PUT request.

Community
  • 1
  • 1
Leantraxxx
  • 4,506
  • 3
  • 38
  • 56
  • I updated the question to clarify. But what I am doing is using rails as a webservice and API, and wish to be able to access the URL: `localhost:3000/specialClickThrough/27`, that would then complete the action in the method specialClickThrough. How can I enable that? – Sauron Jan 25 '15 at 01:31
  • If you try to access `localhost:3000/specialClickThrough/27` from your browser, you will perform a GET not a PUT. You cant perform a PUT just putting the url in your browser. As I said, I recommend you to use Postman (chrome plugin) and select the "PUT option" to perform this kind of actions. Maybe you can do a link as @shoji said in the comment to do a quick check. But you need a better tool (curl, postman) in order to test/use your API more easily – Leantraxxx Jan 25 '15 at 01:42
  • I tried using Postman and setting to "put", but still nothing, see updated question – Sauron Jan 25 '15 at 01:53
  • You are getting now a **422 status**, not a **404** related with `No route matches [GET] "/specialClickThrough/27"`. It's a new error. So, the PUT it's working. – Leantraxxx Jan 25 '15 at 02:06
  • I think you don't have a single question, you have multiple issues. You need to make an effort to solve the problem and make more accurate questions. – Leantraxxx Jan 25 '15 at 02:23
0

In your postman, it appears to be response code 422 which usually comes from a parameter validation error. Of course, because you are hitting the endpoint with no parameters passed in while your route requires a campaign_id (For a PUT request, you need to pass parameters as data, instead of encoded url like GET.)

When you send a put request, make sure that campaign_id is available. (For example, in your postman, try type in campaign_id in the key field right above the send button and some value. It should give you something other than a 422 depending on your implementation)

Edward
  • 1,914
  • 13
  • 26
  • I have done that, setting campaign_id in key...but it still notes 422 OK – Sauron Jan 25 '15 at 04:30
  • are you making a request to `/specialClickThrough/27`? if so, you should be hitting `/specialClickThrough` instead – Edward Jan 25 '15 at 05:15