Jquery 如何让Rails 3链接到:部分工作

Jquery 如何让Rails 3链接到:部分工作,jquery,ruby-on-rails-3,partial-views,Jquery,Ruby On Rails 3,Partial Views,在我的Rails应用程序中,我希望在用户配置文件中有链接到a:partial的链接,这样配置文件的某些部分就不会总是被加载。我(主要)看了各种文章和问题,但我的链接无法正常工作。我当前在加载配置文件时遇到路由错误#Show 下面是我的代码。我是个初学者,如果有人能帮我弄清楚到底发生了什么,我将不胜感激 <div id="tabs"> <ul id="infoContainer"> <li><%= link_to "Link 1", {:par

在我的Rails应用程序中,我希望在用户配置文件中有
链接到
a
:partial
的链接,这样配置文件的某些部分就不会总是被加载。我(主要)看了各种文章和问题,但我的
链接无法正常工作。我当前在加载配置文件时遇到路由错误#Show

下面是我的代码。我是个初学者,如果有人能帮我弄清楚到底发生了什么,我将不胜感激

<div id="tabs">
  <ul id="infoContainer">
    <li><%= link_to "Link 1", {:partial => 'a'}, {:class => "a"}, :remote => true %></li>
    <li><%= link_to "Link 2", {:partial => 'b'}, {:class => "a"}, :remote => true %></li>
    <li><%= link_to "Link 3", profile_profile_c_path(:id => @user.id), :remote => true %></li>
  </ul>
  <div id="tabs-1">
    # I want to load the partials in this div
  </div>
</div><!-- end tabs -->
这是我的`routes.rb文件:

match "/profiles/:id/c" => "profiles#profile_c"
resources :profiles do
  get :profile_c
end
def profile_c
  respond_to do |format|
    format.js { render :layout => false }
  end
end
$( "#tabs" ).html( "<%= escape_javascript( render (:partial => "c", :locals => { :id => @user.id } ) ) %>" );
<% for object in @user.objects %>
<div>
</div>
<% end %>
这是
profiles\u controller.rb中的
profile\u c
操作:

match "/profiles/:id/c" => "profiles#profile_c"
resources :profiles do
  get :profile_c
end
def profile_c
  respond_to do |format|
    format.js { render :layout => false }
  end
end
$( "#tabs" ).html( "<%= escape_javascript( render (:partial => "c", :locals => { :id => @user.id } ) ) %>" );
<% for object in @user.objects %>
<div>
</div>
<% end %>
这是我的
profile_c.js.erb
文件:

match "/profiles/:id/c" => "profiles#profile_c"
resources :profiles do
  get :profile_c
end
def profile_c
  respond_to do |format|
    format.js { render :layout => false }
  end
end
$( "#tabs" ).html( "<%= escape_javascript( render (:partial => "c", :locals => { :id => @user.id } ) ) %>" );
<% for object in @user.objects %>
<div>
</div>
<% end %>
错误显示
没有路由匹配{:action=>“profile_c”,:controller=>“profiles”,:id=>1}

更新:我不再收到错误。我将routes.rb更改为:

resources :profiles do
  get :profile_c, :on => :member
end
以及我的链接到:

<li><%= link_to "Link 3", profile_c_profile_path(:id => @profile.id), :remote => true %></li>
  • @profile.id),:remote=>true%>
  • 让您的路线像:

    resources :profiles do
      get :profile_c, :on => :member
    end
    
    让你的路线像:

    resources :profiles do
      get :profile_c, :on => :member
    end
    

    如果您编写:on=>:collection而不是:on=>:member,那么仍然无法获得与之匹配的路由{:action=>“profile\u c”,“controller=>”profiles“,:id=>1}
    如果您编写:on=>:collection而不是:on=>:member,您的:action=>“profile\u问题”在哪里?编辑您的问题以获得更多详细信息。如果您编写:on=>:collection而不是:on=>:member,请让我们仍然获得
    没有路由匹配{:action=>“profile\u c”,“controller=>”profiles“,:id=>1}
    如果您编写:on=>:collection而不是:on=>:member,您的:action=>“profile\u questions”在哪里?编辑您的问题以获得更多详细信息请联系我们