當我點擊一個鏈接來呈現佈局作爲我實現jQuery UI選項卡的一部分時,我得到ActionController::RoutingError in Profiles#show
。這裏是我的link_to
:使用jQuery UI選項卡和AJAX時的RoutingError
<%= link_to "Messages", :controller => 'profiles', :action => 'profile_messages', :remote => true %>
我ProfilesController:
def profile_messages
@messages = User.find(@profile.user_id).messages
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @messages }
end
end
我profile_messages
ERB佈局:
<div id="tabs-2">
<% for message in @user.messages %>
<div class="message-1">
</div>
<% end %>
</div><!-- end messages -->
的routes.rb:
resources :messages do
get "messages/profile" => :profile_messages
resources :responses
end
我希望發生的是:當你在profile_messages.html.erb
節目點擊創建的鏈接被我link_to
,佈局和在特定的佈局加載的消息。這裏發生了什麼?
UPDATE:添加在Routes.rb
新行給了我一個新的路徑:
message_messages_profile GET /messages/:message_id/messages/profile(.:format) {:action=>"profile_messages", :controller=>"messages"}
於是我在我的個人檔案想這show.html.erb我提出:
<li><%= link_to "Messages", message_messages_profile_path, :remote => true %></li>
這給我一個RoutingError in Profiles#show
- No route matches {:action=>"profile_messages", :controller=>"messages"}
。甚至當我添加以下到我MessagesController
:
def profile_messages
@message = @user.messages.find(params[:user_id])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @messages }
end
end
是吧'資源:messages'或'資源:messages'?我嘗試了兩種方法,仍然在配置文件中顯示RoutingError - ''沒有路由匹配{:action =>「profile_messages」,:controller =>「profiles」,:remote => true}'。去localhost3000/messages/profile給MessagesController#顯示''RecordNotFound'''找不到ID = profile'的消息 – tvalent2
我已經添加了一個更新,以瞭解現在發生了什麼。 – tvalent2
因此,只要它給你'找不到ID = profile'的消息,這意味着你沒有達到正確的路線。也許如果你在資源塊之前移動了'get'。記住,如果你閱讀'rake routes',它看到的東西的順序就是它所經歷的。第一場比賽,它完成了。稍微更新了我的答案。希望這會讓你更接近。 – Travis