Ruby on rails Rails路由获取:this[:id]
我在路由文件中设置正确的路由时遇到问题。 我有一个活动控制器。 在Events Controller中,我有一个名为“people”的操作,看起来有点像这样:Ruby on rails Rails路由获取:this[:id],ruby-on-rails,routes,custom-routes,Ruby On Rails,Routes,Custom Routes,我在路由文件中设置正确的路由时遇到问题。 我有一个活动控制器。 在Events Controller中,我有一个名为“people”的操作,看起来有点像这样: def people @people = Event.find_by_sql(["sql that joins three tables to get the data I need;", params[:id]]) end 在我的路线中,我有: resources :events do collection do
def people
@people = Event.find_by_sql(["sql that joins three tables to get the data I need;", params[:id]])
end
在我的路线中,我有:
resources :events do
collection do
get :somethingelse
get :people
end
end
如果我在“find_by_sql”之前硬编码我的参数[:id],当我访问“../events/people”时,它可以正常工作。但是,如果我尝试执行“../events/5/people”之类的操作,则会出现“No route matches[get]”/events/5/people”错误
我确信我的routes文件中缺少了一些简单的内容。
有人能提供我丢失的零件吗?是的,它不在收藏中,在会员卡上
collection do
get :somethingelse
end
member do
get :people
end
是的,它不在收集上,它在会员上
collection do
get :somethingelse
end
member do
get :people
end
是的,它不在收集上,它在会员上
collection do
get :somethingelse
end
member do
get :people
end
是的,它不在收集上,它在会员上
collection do
get :somethingelse
end
member do
get :people
end
您可以尝试以下方法:
id = 1
User.find_by_sql(['select * from users where id = ?', id])`
您可以尝试以下方法:
id = 1
User.find_by_sql(['select * from users where id = ?', id])`
您可以尝试以下方法:
id = 1
User.find_by_sql(['select * from users where id = ?', id])`
您可以尝试以下方法:
id = 1
User.find_by_sql(['select * from users where id = ?', id])`