开发者

Routing error from jQuery UI tabs with ajax

I'm using Rails and jQuery UI to implement tabs in each user's profile. I've got it working without ajax - with ajax, things go south. I'm new to Rails and jQuery and am hoping someone can help me identify what's go开发者_开发技巧ing wrong.

  • <div id="tabs-1"> is the first tab and it is associated with ProfilesController by default. That works by using an <a href>.
  • <div id="tabs-2"> would access MessagesController and load a partial show_messages that loads @user.messages.

What happens instead is that when I click "Messages" I get an ActionController::Routing error in Profiles#show.

No route matches {:action=>"show", :controller=>"messages", :id=>[#<Message id: 3, user_id: 2,...>, #<Message id: 4, user_id: 2,...">]}

My code is below:

application.js:

$(function() {
    $( "#tabs" ).tabs({
        ajaxOptions: {
            error: function( xhr, status, index, anchor ) {
                $( anchor.hash ).html(
                    "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                    "If this wouldn't be a demo." );
            }
        }
    });
});

My profile show.html.erb:

<div id="tabs">
    <ul id="infoContainer">
        <li><a href="#tabs-1"></a></li>
        <li><%= link_to "Messages", message_path(@user.messages) %></a></li>
    <ul>
    <div id="tabs-1">
    </div>
</div>

My _show_messages partial in MessagesController:

<div id="tabs-2">
    <% for 'message' in @user.messages %>
        <div class="message">
        </div>
    <% end %>
</div>


in show.html.erb message_path(@users.messages) is wrong. Try messages_path which should point to the index action of the messages controllr. Here I am assuming you are using the standard Rails convection for messages routes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜