rails 4 link_to post method

215 views
Skip to first unread message

Me

unread,
Mar 29, 2014, 1:02:45 PM3/29/14
to rubyonra...@googlegroups.com
I have a rails 4 app that has a link_to with a post method but I keep getting:

No route matches [GET] "/payments/136330"


<%= link_to("Buy Now", buy_path(list_item), :method => :post) %>

Ideas??

Me

unread,
Mar 29, 2014, 1:04:27 PM3/29/14
to rubyonra...@googlegroups.com
Route,  post 'payments/:list_item_id', to: 'payments#buy', :as => :buy

Arun kant sharma

unread,
Mar 29, 2014, 1:12:09 PM3/29/14
to rubyonra...@googlegroups.com
Please change your name from "Me" to something else. It's confusing.

Loganathan Sellapa

unread,
Mar 29, 2014, 1:33:36 PM3/29/14
to rubyonra...@googlegroups.com

Hi,

Can you copy your full routes.rb, I believe you should place the route at before the route
"resources :payment"

Regards,
Logan

Sent from mobile device

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/21350ab3-a33d-41cb-9061-e103db36b31b%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Chris Habgood

unread,
Mar 29, 2014, 2:14:50 PM3/29/14
to rubyonra...@googlegroups.com
That is the only route for that controller.


--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/3kI7VkfKp4Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.

To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
"In matters of style, swim with the current; in matters of principle, stand like a rock." 
Thomas Jefferson

dasibre

unread,
Mar 30, 2014, 8:29:14 AM3/30/14
to rubyonra...@googlegroups.com
Post your routes.rb file

mike2r

unread,
Mar 30, 2014, 10:58:50 AM3/30/14
to rubyonra...@googlegroups.com


On Saturday, March 29, 2014 1:02:45 PM UTC-4, Me wrote:
a little difficult without a full log, but a strong, educated guess would be that there's a javascript problem.  Links always generate a GET action.  When you use :method => :post, there's javascript in the rails javascript file that detects it, re-writes the link as a form, and submits it as a post.  If that javascript is missing, or if there's a javascript error that prevents it from executing, you'll get the message you're getting above.

@mike2r

Chris Habgood

unread,
Apr 6, 2014, 2:29:56 PM4/6/14
to rubyonra...@googlegroups.com
Thanks, here is the link generated,  <a data-method="post" href="/list_items/136298/buy" rel="nofollow">Buy Now</a>

Routes:

resources :users
  resources :list_items do
    post :buy, :on => :member
  end

  root 'list_items#index'

ERB:

<%= link_to("Buy Now", buy_list_item_path(list_item), :method => 'post') %>


--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/3kI7VkfKp4Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Walter Lee Davis

unread,
Apr 6, 2014, 4:55:26 PM4/6/14
to rubyonra...@googlegroups.com

On Apr 6, 2014, at 2:29 PM, Chris Habgood wrote:

> Thanks, here is the link generated, <a data-method="post" href="/list_items/136298/buy" rel="nofollow">Buy Now</a>
>
> Routes:
>
> resources :users
> resources :list_items do
> post :buy, :on => :member
> end
>
> root 'list_items#index'
>
> ERB:
>
> <%= link_to("Buy Now", buy_list_item_path(list_item), :method => 'post') %>
>

Confirm that rails.js is being loaded. Without it, the unobtrusive stuff doesn't work.

Walter

>
> On Sun, Mar 30, 2014 at 9:58 AM, mike2r <mr...@kalanitech.com> wrote:
>
>
> On Saturday, March 29, 2014 1:02:45 PM UTC-4, Me wrote:
> I have a rails 4 app that has a link_to with a post method but I keep getting:
>
> No route matches [GET] "/payments/136330"
>
>
> <%= link_to("Buy Now", buy_path(list_item), :method => :post) %>
>
> Ideas??
>
> a little difficult without a full log, but a strong, educated guess would be that there's a javascript problem. Links always generate a GET action. When you use :method => :post, there's javascript in the rails javascript file that detects it, re-writes the link as a form, and submits it as a post. If that javascript is missing, or if there's a javascript error that prevents it from executing, you'll get the message you're getting above.
>
> @mike2r
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/3kI7VkfKp4Q/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/70d6b54d-d843-4d46-a7a1-3381774cb5ca%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> "In matters of style, swim with the current; in matters of principle, stand like a rock."
> Thomas Jefferson
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAKohUFw-oMOEoa92ESoKW39AwBhs56MYjwsZ1hikEzryydeY8Q%40mail.gmail.com.

Chris Habgood

unread,
Apr 6, 2014, 5:09:37 PM4/6/14
to rubyonra...@googlegroups.com
jquery and jquery_ujs are loaded.  it is a rails 4 app.



For more options, visit https://groups.google.com/d/optout.

Frederick Cheung

unread,
Apr 6, 2014, 5:16:59 PM4/6/14
to rubyonra...@googlegroups.com


On Sunday, April 6, 2014 7:29:56 PM UTC+1, Me wrote:
Thanks, here is the link generated,  <a data-method="post" href="/list_items/136298/buy" rel="nofollow">Buy Now</a>


That's not the same url as the once mentioned in the error. Is the post request completing OK and then redirecting to a non-existent url?

Fred

Chris Habgood

unread,
Apr 6, 2014, 5:20:37 PM4/6/14
to rubyonra...@googlegroups.com
The one I posted was a slightly different one but still gives me the same error.  It does not seem to recognize the link is a 'POST" even though the actual link on the page is a post.

No route matches [GET] "/list_items/136327/buy"


The action 'buy' is in the liat_items_controller.


--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/3kI7VkfKp4Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Frederick Cheung

unread,
Apr 7, 2014, 7:37:31 AM4/7/14
to rubyonra...@googlegroups.com


On Sunday, April 6, 2014 10:20:37 PM UTC+1, Me wrote:
The one I posted was a slightly different one but still gives me the same error.  It does not seem to recognize the link is a 'POST" even though the actual link on the page is a post.

You'll send people round in circles if you're mixing up different urls & different errors. As others have said, this sounds suspicious like a javascript error. Check your browser console for javascript errors. You might also try sticking some (javascript) breakpoints in the rails ubobtrusive js code, to check what it is doing.

Fred

 

No route matches [GET] "/list_items/136327/buy"


The action 'buy' is in the liat_items_controller.
On Sun, Apr 6, 2014 at 4:16 PM, Frederick Cheung <frederic...@gmail.com> wrote:


On Sunday, April 6, 2014 7:29:56 PM UTC+1, Me wrote:
Thanks, here is the link generated,  <a data-method="post" href="/list_items/136298/buy" rel="nofollow">Buy Now</a>


That's not the same url as the once mentioned in the error. Is the post request completing OK and then redirecting to a non-existent url?

Fred

--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/3kI7VkfKp4Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages