Week 2: Rails Models

You will code along with Matt as he builds the application. Do what he does, pause the video if you need to catch up or explore something further. Hop into the chat room to ask questions as you have them, or send emails to learn@thoughtbot.com. We...
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/week-2-rails-models

I keep getting the mass assignment error. Deck.new and deck.name = “Japanese” worked just fine, but I keep getting errors with adding “Russian”.

Are you using Rails 4? Is the error on on the word “Russian” or others too? Did you add a strong params method?

It’s other too. Yes, rails 4.

It’s actually 4.2

If you’re getting an ActiveModel::ForbiddenAttributesError when trying to create a new deck, you’re probably using Rails 4 which introduced strong parameters.

You can implement the create method as follows:

class DecksController < ApplicationController

  ...

  def create
    @deck = Deck.new(deck_params)
    @deck.save
    redirect_to "/decks"
  end


  private

  def deck_params
    params.require(:deck).permit(:name)
  end
end

Similarly, the syntax for the confirmation alert on the Delete button is slightly different in Rails 4. I had to write it as follows to get it to work:

<%= link_to 'Delete', "/decks/#{deck.id}", method: :delete, data: {confirm: 'Are you sure?'} %>

Hope this helps!

EDIT: found my problem. I needed to include the line “gem ‘coffee-script-source’, ‘1.8.0’” in my gemfile. This is apparently an issue with running Rails on a Windows machine. I found this solution at this Stack Overflow thread.

I’m having trouble with the delete function. I’m doing this class half on my home Windows machine, and half on a linux laptop, both running RubyMine and Rails 3.2.21. My windows machine refuses to show the Confirmation popup or allow a DELETE call via link_to (but my Linux machine works as shown in the video). If I change link_to to button_to, I can get the DELETE call to go through, but I still don’t get a confirmation box. The HTML appears to be generating correctly, but when I look at the information in the server command prompt, it shows nothing about the confirmation box.

My popup blocker excludes localhost. I haven’t been able to find anything through the great sage Google. I don’t get any errors, it just doesn’t work. I appreciate any guidance I can get.