#link_to is throwing error - ArgumentError: arguments passed to url_for can't be handled.

1,258 views
Skip to first unread message

Arup Rakshit

unread,
Feb 18, 2015, 12:46:54 PM2/18/15
to rubyonra...@googlegroups.com
Hi,

I have the below resource table Comment controller :

[arup@app]$ rake routes | grep comments
comments GET /comments(.:format) comments#index
POST /comments(.:format) comments#create
new_comment GET /comments/new(.:format) comments#new
edit_comment GET /comments/:id/edit(.:format) comments#edit
comment GET /comments/:id(.:format) comments#show
PATCH /comments/:id(.:format) comments#update
PUT /comments/:id(.:format) comments#update
DELETE /comments/:id(.:format) comments#destroy

Now, I am trying to figure out what I read from the guide - http://guides.rubyonrails.org/v4.1.8/routing.html#creating-paths-and-urls-from-objects

=======
If you wanted to link to just a magazine:....
For other actions, you just need to insert the action name as the first element of the array:...
=======

I tried -

helper.link_to("Show comment", [Comment.first], method: :get)
helper.link_to("Show comment", Comment.first, method: :get)
helper.link_to("Show comment", [:show, Comment.first])
helper.link_to("Show comment", Comment.first, method: :get)

Always I'm getting the error as : ArgumentError: arguments passed to url_for can't be handled. Please require routes or provide your own implementation

Any idea what am I doing wrong ? I am not getting the result as guide promised. :-)

--
================
Regards,
Arup Rakshit
================
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

--Brian Kernighan

tamouse pontiki

unread,
Feb 19, 2015, 12:29:51 AM2/19/15
to rubyonra...@googlegroups.com
If I call link_to with helper like you are from rails console (running pry-rails), I get the same error. But when I put it into a view, it works....

--
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/1429708.zPV1iYpq3S%40linux-wzza.site.
For more options, visit https://groups.google.com/d/optout.

Arup Rakshit

unread,
Feb 19, 2015, 10:25:35 PM2/19/15
to rubyonra...@googlegroups.com
On Wednesday, February 18, 2015 11:27:47 PM tamouse pontiki wrote:
> If I call link_to with helper like you are from rails console (running
> pry-rails), I get the same error. But when I put it into a view, it
> works....
>

Thanks. Then I'll create an issue ticket for this.

Javix

unread,
Feb 20, 2015, 3:06:35 AM2/20/15
to rubyonra...@googlegroups.com


On Wednesday, 18 February 2015 18:46:54 UTC+1, Arup Rakshit wrote:
Hi,

I have the below resource table Comment controller :

[arup@app]$ rake routes | grep comments
      comments    GET    /comments(.:format)          comments#index
                           POST   /comments(.:format)          comments#create
   new_comment  GET    /comments/new(.:format)      comments#new
  edit_comment   GET    /comments/:id/edit(.:format) comments#edit
       comment     GET    /comments/:id(.:format)      comments#show
                           PATCH  /comments/:id(.:format)      comments#update
                           PUT    /comments/:id(.:format)      comments#update
                           DELETE /comments/:id(.:format)      comments#destroy

Now, I am trying to figure out what I read from the guide - http://guides.rubyonrails.org/v4.1.8/routing.html#creating-paths-and-urls-from-objects

=======
If you wanted to link to just a magazine:....
For other actions, you just need to insert the action name as the first element of the array:...
=======

I tried -

helper.link_to("Show comment", [Comment.first], method: :get)
helper.link_to("Show comment", Comment.first, method: :get)
helper.link_to("Show comment", [:show, Comment.first])
helper.link_to("Show comment", Comment.first, method: :get)

Always I'm getting the error as : ArgumentError: arguments passed to url_for can't be handled. Please require routes or provide your own implementation

Any idea what am I doing wrong ? I am not getting the result as guide promised. :-)

Why do you prefix link_to with 'helper ? To point to a comments#show, just use
link_to 'Show comment", Comment.first


or
link_to 'Show comment", comment


if you have a comment instance variable defined in 'show' action of the CommentsController.

Your Comment is a RESTful resource and have all the standard RESTful methods defined by default according to your routes. So, no need to precise the GET in your link_to helper in the view.

Arup Rakshit

unread,
Feb 20, 2015, 1:07:52 PM2/20/15
to rubyonra...@googlegroups.com
> if you have a *comment *instance variable defined in 'show' action of the
> CommentsController.
>
> Your Comment is a RESTful resource and have all the standard RESTful
> methods defined by default according to your routes. So, no need to precise
> the GET in your link_to helper in the view.

My point was in rails console, not inside the erb template.
Reply all
Reply to author
Forward
0 new messages