Comments (12)
course_params
这个方法的用法在:用户更新或者新建一个课程的时候,通过这个方法能捕获用户填写的信息,并不适合用在这里,这个地方不需要那么多信息,只要知道该课程的id即可,然后将这个课程的open字段更新为true就行
from courseselect.
用此方法已解决,有你要注意的的地方,
def course_params
params.require(:course).permit(:course_code, :name, :course_type, :teaching_type, :exam_type,
:credit, :limit_num, :class_room, :course_time, :course_week)
end
在这个方法中的permit的参数应该也要添加 你刚才新添加的课程的属性open相关的字段,希望能帮助到你。
from courseselect.
谢啦,不过我还是没能解决,一定是还有什么没弄好
from courseselect.
如果这个方法不行的话 你可以用这个,只对course的open字段进行update,代码是这样的(我用的是course_open来标记课程开放或关闭的)
@course.update_attributes(:course_open=>"false")
这个方法只需要在open 和close函数中设置这上述代码中的括号中的true或者false 即可 原来project的其地方不需要修改。
from courseselect.
@PENGZhaoqing @songmingtao 显示为
ActiveRecord::UnknownAttributeError in CoursesController#open
unknown attribute 'course_open' for Course.
这要怎么改?谢了
def open
@course=Course.find_by_id(params[:id])
@course.update_attributes(:course_open=>"true")
redirect_to course_path, flash: {:success => "已经成功开放课程:#{@course.name}"}
end
from courseselect.
说明你的course表里没有:course_open这个字段,也就是你数据迁移没成功。
检查你的迁移文件是否含有这个字段,然后运行rake db:migrate:reset
和rake db:seed
from courseselect.
@songmingtao @jewhau 布尔变量请直接用true和false,不需要用引号括起来,引号括起来的是字符串,除非你字段类型申明的是字符串
from courseselect.
class AddOpenAttribute < ActiveRecord::Migration
add_column :courses, :course_open, :boolean, :default =>false
end
是这样子吗? @PENGZhaoqing
from courseselect.
嗯,运行迁移指令成功后一般会有提示
from courseselect.
@PENGZhaoqing 我申请的是boolean变量,用的也是加双引号,但结果显示正确,没有报错(如果在你那里报错,可能就是版本的问题)
from courseselect.
@PENGZhaoqing @jewhau
jewhau 的代码是:
class AddOpenAttribute < ActiveRecord::Migration
add_column :courses, :course_open, :boolean, :default =>false
end
我想问,
(1)我将:courses删去,直接写:open,如下:
add_column :open, :boolean, :default =>false
我这样做,行不行?
(2)另外,如果保留courses, 但是后面的不用:course_open,而直接写:open, 即
add_column :courses, :open, :boolean, :default =>false
这样行不行?
(3)其实我不是很明白add_column的具体含义。
from courseselect.
首先,你要知道什么是数据表,http://jingyan.baidu.com/article/414eccf60033f76b431f0ac8.html
column是列的意思,add_column也就是相当于在表里增加了一个新的列(通常说属性),在上面网址里,如果你用 add_column :scores, :physics, :int
,这就表明你要在这个成绩表里增加一个新的列(物理成绩属性),如果你不加:scores
(表名),那么Rails怎么知道你到底要往哪个表里增加一列,因为还有很多其他的数据表啊,你总不能在每个表里都加上:physics
这一列吧
至于你写:physics
或者是:physics_score
,这都无所谓,这就是个变量而已,区别就是:当你要获得这个属性值时,要用@student.physics
或者@student.physics_score
来访问储存的值
API: http://api.rubyonrails.org/classes/ActiveRecord/Migration.html
from courseselect.
Related Issues (20)
- 关于在rails视图中使用二维数组 HOT 2
- redirect_to HOT 1
- 请问如何将数据导入到数据库中 HOT 2
- 导出课程列表的时候提示路由错误 HOT 2
- 关于删除选课的参数问题 HOT 8
- 在html文件中增加搜索框 HOT 7
- github在pull request时出现conflict HOT 1
- cloud9上执行rake db:migrate时的问题 HOT 1
- 查询数据库的问题 HOT 1
- 下载excel文件自动跳转微软url问题
- form表单submit按钮无法提交,除非刷新一次 HOT 3
- sudo service postgrsql start 出现问题 HOT 1
- heroku 部署的问题 HOT 1
- rake db:seed rake aborted! Email has already been taken HOT 1
- gem install nokogiri -v '1.6.8' HOT 1
- 执行rake test 报错 HOT 4
- heroku上部署以后无法发送邮件 HOT 1
- 在heroko无法成功branch HOT 5
- An error occurred while installing pg (0.18.4) HOT 8
- bundle instll error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from courseselect.