Giter Site home page Giter Site logo

Comments (12)

PENGZhaoqing avatar PENGZhaoqing commented on September 4, 2024

course_params 这个方法的用法在:用户更新或者新建一个课程的时候,通过这个方法能捕获用户填写的信息,并不适合用在这里,这个地方不需要那么多信息,只要知道该课程的id即可,然后将这个课程的open字段更新为true就行

from courseselect.

codewaltz1994 avatar codewaltz1994 commented on September 4, 2024

用此方法已解决,有你要注意的的地方,

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.

jewhau avatar jewhau commented on September 4, 2024

谢啦,不过我还是没能解决,一定是还有什么没弄好

from courseselect.

codewaltz1994 avatar codewaltz1994 commented on September 4, 2024

如果这个方法不行的话 你可以用这个,只对course的open字段进行update,代码是这样的(我用的是course_open来标记课程开放或关闭的)

@course.update_attributes(:course_open=>"false")

这个方法只需要在open 和close函数中设置这上述代码中的括号中的true或者false 即可 原来project的其地方不需要修改。

from courseselect.

jewhau avatar jewhau commented on September 4, 2024

@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.

PENGZhaoqing avatar PENGZhaoqing commented on September 4, 2024

说明你的course表里没有:course_open这个字段,也就是你数据迁移没成功。

检查你的迁移文件是否含有这个字段,然后运行rake db:migrate:resetrake db:seed

from courseselect.

PENGZhaoqing avatar PENGZhaoqing commented on September 4, 2024

@songmingtao @jewhau 布尔变量请直接用true和false,不需要用引号括起来,引号括起来的是字符串,除非你字段类型申明的是字符串

from courseselect.

jewhau avatar jewhau commented on September 4, 2024
class AddOpenAttribute < ActiveRecord::Migration
    add_column :courses, :course_open, :boolean, :default =>false
end

是这样子吗? @PENGZhaoqing

from courseselect.

PENGZhaoqing avatar PENGZhaoqing commented on September 4, 2024

嗯,运行迁移指令成功后一般会有提示

from courseselect.

codewaltz1994 avatar codewaltz1994 commented on September 4, 2024

@PENGZhaoqing 我申请的是boolean变量,用的也是加双引号,但结果显示正确,没有报错(如果在你那里报错,可能就是版本的问题)

from courseselect.

tangmaomao16 avatar tangmaomao16 commented on September 4, 2024

@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.

PENGZhaoqing avatar PENGZhaoqing commented on September 4, 2024

首先,你要知道什么是数据表,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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.