开发者

Routing in Ajax petition in Rails 2

I have the following in my view:

$('#anID tr').click(function () {
        $.ajax({
            type: 'GET',
            url: '/tickets/extended_info',
            dataType: 'script',
            data: { id: $(this).find('td:first').html() }
        });
    });

and this in my tickets controller:

def extended_info(id)
    puts ">>>>>>>>>>>>>>> " + id.to_s
  end

But I always get 404 not found from the ajax request.

I think I'm missing something in my routes file... I tried several thin开发者_JAVA技巧gs, but nothing.

Any ideas?

>>>>>>>>>>>>>>>>>>>>> RESOLVED <<<<<<<<<<<<<<<<<<<<<<<<<

I had to add:

map.extendedInfo '/extended_info/:id', :controller => 'tickets', :action => 'extended_info'

to my routes file.

Also, I was using "GET" in my ajax call in my JavaScript ... I changed to POST and now it's working =)


Really seems like routing trouble. Do you have appropriate row for /tickets/extended_info path in your routes.rb? If so, can you post it here?

I suppose something like this

get "/ticket/extended_info", :to => "tickets_controller#extended_info"

in routes.rb and your action on controller should be just

def extended_info
  puts params[:id].inspect
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜