jendiamond / railsgirls-signup

https://railsgirls-signup.herokuapp.com
3 stars 3 forks source link

Add Question & Answers Models #2

Closed jendiamond closed 8 years ago

jendiamond commented 8 years ago

$ rails g model Answer user_id:integer question_id:integer

$ rails g scaffold Question boolean_question:boolean string_question:string text_question:text integer_question:integer

User.rb

has_many :answers
has_many :questions, through: :answers

Question.rb

has_many :answers
has_many :users, through: :answers

Answer.rb (Join table)

belongs_to :user
belongs_to :question

create_table "answers", force: :cascade do |t| t.integer "user_id" t.integer "question_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end

create_table "questions", force: :cascade do |t| t.boolean "boolean_question" t.string "string_question" t.text "text_question" t.integer "integer_question" t.datetime "created_at", null: false t.datetime "updated_at", null: false end


Add Questions to the Form

http://stackoverflow.com/questions/2182428/rails-nested-form-with-has-many-through-how-to-edit-attributes-of-join-model

<%= form_for(@topic) do |topic_form| %>
  ...fields...
  <%= topic_form.fields_for :linkers do |linker_form| %>
    ...linker fields...
    <%= linker_form.fields_for :article do |article_form| %>
      ...article fields...
jendiamond commented 8 years ago

https://www.youtube.com/watch?v=PD0-efs7s_A

jendiamond commented 8 years ago

Add questions for rating to the form

You don't need to have experience to attend, just excitement and an interest. We just need to know a few things to help us group the students better at the event.

$ rails generate migration add_columns_to_questions newbie:boolean html_css:boolean tutorials:boolean study_group:boolean program:boolean website:boolean work:boolean bootcamp:boolean compsci:boolean rlsgrl_rlsbrg:boolean

$ rails generate migration add_more_columns_to_questions continue:string support:string experience:string

newbie html_css tutorials study_group program website work bootcamp compsci rlsgrl_rlsbrg continue support experience


  1. I am a total newbie :)
  2. I am familiar with HTML / CSS
  3. I have done online Ruby / Rails tutorials
  4. I attend Study Group
  5. I have written a program (any language)
  6. I have created a website and launched it on the web

  1. I currently work in tech
  2. I have attended an immersive bootcamp program
  3. I have or am getting a CS degree
  4. I have attended Rails Girls / Railsbridge

  1. Do you think you will continue learning to program after the workshop?
  2. Do you have any people to support you with this goal?
  3. Previous Experience. Do you have any previous programming experience? Please explain. What languages? For how long? What did you make? In school or on your own? Do you currently program? Did you attend a code school? This helps us group students when working in small groups.
jendiamond commented 8 years ago

http://blog.teamtreehouse.com/what-is-a-has_many-through-association-in-ruby-on-rails-treehouse-quick-tip

User has_many :subscriptions has_many :magazines, through: :subscriptions

Magazine has_many :subscriptions has_many :users, through: :subscriptions

Subscription belongs_to :user belongs_to :magazine

Join table(subscription)

user = User.first magazine = Magazine.first user.subscriptions.create(magizine: magazine) user.magazines