我有一个学校页面,点击时有标签,可以调出微博。问题是我认为我没有正确地路由它,我觉得这个白痴试图解决这个问题而不是成功。如果有人有任何建议请随时帮助我!非常感谢你!
的routes.rb
get "/schools/:id/mostrecent_schools" => "users#microposts", :as => "mostrecent_schools"
学校管理员
def mostrecent
@school = School.find_by_slug(request.referer.gsub('http://localhost:3000/','')).id
@microposts = @user.microposts.paginate(:per_page => 10, :page => params[:page])
respond_to do |format|
format.html
format.js
end
end
标签HTML
li class='StreamTab StreamTabRecent active'>
<%= link_to 'Most Recent', mostrecent_schools_path, :remote => true, :class => 'TabText' %>
</li>
<div id='ContentBody'>
<div id='ajax'></div>
<%= render 'users/microposts', :microposts => @microposts %>
</div>
mostrecent.js
$("#ajax").hide();
$("#ContentBody").html('<%= escape_javascript(render :partial => "users/microposts" )%>');
修改 * 的routes.rb *
Projects::Application.routes.draw do
resources :pages
resources :application
resources :schools
resources :microposts
resources :comments
resources :users
resources :sessions
resources :password_resets
resources :relationships, only: [:create, :destroy]
resources :users do
member do
get :following, :followers
end
end
resources :microposts do
member do
post :vote_up, :unvote
end
end
resources :microposts do
member do
post :upview
end
end
resources :microposts do
resources :comments
end
get "schools/:page/mostrecent" => "schools#mostrecent", :as => "mostrecent_schools"
root to: "pages#index"
答案 0 :(得分:2)
根据我的理解,您的routes.rb应该看起来像这样
我的最后一次尝试
将您的routes.rb更改为此
get "schools/mostrecent/new/:page" => "schools#mostrecent", :as => "mostrecent_schools"
并在您的控制器中编辑此行。如果这不起作用,那么我放弃
@school = School.find_by_slug(request.referer.gsub('http://localhost:3000/','')).params[:page]
虽然这不是做事的宁静方式,但据我所知,由于用户属于学校并且微博属于用户,因此您不应将学校微博和用户定义为简单:资源。
请参阅[Rails路由指南](请参阅http://guides.rubyonrails.org/routing.html)for更多详细信息。