【发布时间】:2015-11-24 11:43:35
【问题描述】:
我关注this tutorial。
我无法理解rails 中的params[]。请不要向我提供rails 指南的链接。我已经读过,仍然不清楚。我的疑惑是
- 我可以给出什么论据
- 什么是 params[:folder] & params[:id]
- 如果它是我们传递的列名,那么我的表中没有文件夹列。列在我的文件夹表中:id、name、created_at、updated_at
-
我使用的是 rails 4.2.4,所以我读过的一些地方 attr_accessible 被使用了,但现在它已经过时了。那么用什么来代替 attr_accessible 呢?
class FoldersController < ApplicationController before_filter :authenticate_user! def index @folders = current_user.folders end def show @folder = current_user.folders.find(params[:id]) end def new @folder = current_user.folders.new end def create @folder = current_user.folders.new(params[:folder]) end end
这是我的第二个控制器。我怀疑这里的folder_id是什么
class HomeController < ApplicationController
def browse
#get the folders owned/created by the current_user
@current_folder = current_user.folders.find_by_id(params[:folder_id])
end
end
【问题讨论】:
-
params包含请求参数。如果您导航到/folders/1234?foo=bar,那么params[:id]将是1234和params[:foo]将等于"bar"。
标签: ruby-on-rails ruby