В моем приложении на Rails я хочу, чтобы в профиле пользователя были ссылки, которые link_to
a :partial
, чтобы определенные части профиля не всегда загружались.Я просмотрел различные статьи и вопросы (в основном , этот ), но не могу заставить работать link_to
.В настоящее время я получаю ошибку маршрутизации при загрузке Profiles # 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 -->
Я использую последний link_to
в качестве примера:
<li><%= link_to "Link 3", profile_profile_c_path(:id => @user.id), :remote => true %></li>
Вот мой файл `rout.rb:
match "/profiles/:id/c" => "profiles#profile_c"
resources :profiles do
get :profile_c
end
Вот действие profile_c
в profiles_controller.rb
:
def profile_c
respond_to do |format|
format.js { render :layout => false }
end
end
Вот мой profile_c.js.erb
файл:
$( "#tabs" ).html( "<%= escape_javascript( render (:partial => "c", :locals => { :id => @user.id } ) ) %>" );
Вот мой _c.html.erb
частичный:
<% for object in @user.objects %>
<div>
</div>
<% end %>
Ошибка показывает No route matches {:action=>"profile_c", :controller=>"profiles", :id=>1}
ОБНОВЛЕНИЕ: Я больше не получаю ошибку.Я изменил мой route.rb на:
resources :profiles do
get :profile_c, :on => :member
end
И мой link_to на:
<li><%= link_to "Link 3", profile_c_profile_path(:id => @profile.id), :remote => true %></li>