Restful Link_to

Hello

i would like a new vote with link_to , this my code
<%= link_to(‘rate it’, vote_url(:id => @faq.id, :score => 1), :html => {
:method => :post }) %>

Each time i am redirect to show method and not create method :frowning:

Can u help me ?

Thanks

Not sure if I’m giving you the right answer but according to this little
chart
orders_url /posts GET index orders_url /posts POST create
order_url /posts/:id GET show order_url /posts/:id PUT update
order_url /posts/:id DELETE destroy new_order_url /posts/new GET new
edit_order_url /posts/:id;edit GET edit
it looks like you should be doing a GET to new.
At least that is how I’ve found it to work new goes into create. No
it’s
not the best explanation.
Hope it helps.

Stuart

On 10/12/06, Bolo [email protected] wrote:

Can u help me ?

Thanks


Posted via http://www.ruby-forum.com/.


Hello Dark

it looks like you should be doing a GET to new.
At least that is how I’ve found it to work new goes into create. No
it’s
not the best explanation.

don’t really understand your explanation.:frowning:
And i don’t want to do a Get but a POST with a link_to

Bolo, I believe you have your attributes wrong. Try this:

<%= link_to ‘rate it’, vote_url(:id => @faq.id, :score => 1), :post =>
true %>

I am concerned about your faq.id being sent as the id… shouldn’t it
be :faq_id => @faq.id if you are trying to create a new vote object?

hello Carl,

try your code
<%= link_to ‘rate it’, vote_url(:faq_id => @faq.id, :score => 1), :post
=> true %>

This link redirect me here (show method and not create method)
http://localhost:3000/votes/41?faq_id=41&score=1
:frowning:

Bolo, I don’t know why you are continuing to use post. It’s not the
right
method.

Stuart

On 10/12/06, Bolo [email protected] wrote:

:frowning:


Did it redirect you? IE It created your vote and then redirected you
to show? Or did it just send you to show?

Please post the entire contents of the link tag. Also, what is the
correct URL you are aim for?

Stuart,

He is trying to CREATE something, so POST is definitely the way to go.
You don’t want votes to be created by some web crawler or some crazy
Google Caching tool do you?

The URL that is generated by the link_to has the params in the URL but
I it is not working for some reason.

Carl

On 10/12/06, Bolo [email protected] wrote:

And i don’t want to do a Get but a POST with a link_to
Okay, here is the link to what I posted:

http://david.goodlad.ca/articles/2006/08/02/simply_restful-in-rails-core

It will help you understand the routes better.

Stuart


On 10/12/06, Carl F. [email protected] wrote:

Carl

Thanks Carl, I was going by the list of the 7 methods / routes. I guess
I’m wrong.
Stuart

Stuart… I don’t think you were wrong at all. If you are trying to
get to the form to enter data (which is ‘new’), then you are correct.
However, if you are trying to actually create the object from the
link, then you would want to go this other route. Who knows what Mr.
Bolo wants :slight_smile:

Thanks Carl! I’m far from a rest initiate, even though I took the plunge
to
make my app as restful as possible.
Good to know about the link , sure at some point I’ll need it :slight_smile:

Stuart

On 10/12/06, Carl F. [email protected] wrote:


Ok, I just asked Rick O. (core member) and he said this won’t
work/isn’t supported. Primarily because it isn’t really ‘RESTful’. But
that doesn’t mean you can’t go old school on it and do it that way. So
create an add_vote method and grab the params and go on about your
day. But still use the :post => true for the reasons I explained to
Stuart.

If you take the old school route you will be allowing delete operation
by manipulating the URL
right?

Bala,

No. By ‘old school’ I mean that you create a method that has very
specific functionality and does not directly map to CRUD.

Carl

Yeh boys

  1. i am girl :slight_smile:
  2. i would like a create a object form link

Ok, I just asked Rick O. (core member) and he said this won’t
work/isn’t supported. Primarily because it isn’t really ‘RESTful’. But
that doesn’t mean you can’t go old school on it and do it that way. So
create an add_vote method and grab the params and go on about your
day. But still use the :post => true for the reasons I explained to
Stuart.

Okidoki Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs