We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
def new @job = Job.new end
def create @job = Job.new(job_params) if @job.save redirect_to admin_jobs_path else render :new end end
这段代码应如何理解?new方法是ruby内置的吗? 这段代码中,Job.new 和 Job.new(job_params),一个是传参数的,一个是无参数。为什么?
The text was updated successfully, but these errors were encountered:
@job 是变量 = 可以赋予变量后面的值 Job.new是一个动作,对应的是到页面上打开jobs/new 的页面 因为新建页面是不存在数据的,所以不需要有参数
同样在create里面是同时存在job的页面的新增加的内容的 内容就在job_params 这个内容在 private def job-params params_require(:job).permit(:job,:description,:wage_upper_bound) end 里面定义了动作 也就是job_params 调出的就是(:job,:description,:wage_upper_bound) Job.new(job_params)就是把你在新建页面上填的内容赋予给了@job这个变量了 下面如果这个变量已经保存了if @job.save redirect_to admin_jobs_path 回到管理员的主页 如果没有保存 就去新建页面继续新增内容 这部分内容是我对CRUD 和Restful的理解 如果有不对的地方请老师指出来 如果没问题 我可以给有困惑的同学讲一讲我的理解 另外我的这部分理解是今天从环境设置开始又从头看了一遍教材看懂的 这时候才发现原来做的时候 自己的眼睛和脑子居然自动跳过去了那么多的知识点 也许这就是拼图游戏吧
Sorry, something went wrong.
非常清晰的解释,感谢!我也得回去重头看一遍教程。
No branches or pull requests
def new
@job = Job.new
end
def create
@job = Job.new(job_params)
if @job.save
redirect_to admin_jobs_path
else
render :new
end
end
这段代码应如何理解?new方法是ruby内置的吗?
这段代码中,Job.new 和 Job.new(job_params),一个是传参数的,一个是无参数。为什么?
The text was updated successfully, but these errors were encountered: