0

I generated a scaffold for a To-Do List app, and I left out some columns to add later.

I ran the command to create a migration to add a new column named client and I changed my files so that it shows on the projects index and form, but when i enter something into the client field and submit, it doesn't save the information and remains blank..

Update 1:

Here is whats in my routes:

'

Rails.application.routes.draw do
  root      :to => 'projects#index'
  resources :projects
end

'

Here is my index view:

'

<h1 id="title">Project List</h1>



<table>
  <thead>
    <tr id="headers">
      <th>Title</th>
      <th>Client</th>
      <th>Description</th>
      <th>Hours</th>
      <th>Done</th>
      <th colspan="3"></th>
    </tr>
  </thead>


  <tbody class="col-md-2" id="listItems">
    <% @projects.each do |project| %>
      <tr id="table">
        <td><%= project.title %></td>
        <td><%= project.client %></td>
        <td><%= project.description %></td>
        <td><%= project.hours %></td>
        <td><%= project.done %></td>

        <td><%= link_to " #{image_tag('show.png')}".html_safe, project, id:'showButton' %></td>


        <td><%= link_to " #{image_tag('edit.png')}".html_safe, edit_project_path(project), id:'editButton' %></td>

        <td><%= link_to " #{image_tag('destroy.png')}".html_safe, project, id:'destroyButton', method: :delete, data: { confirm: 'Are you sure?' } %></td>

      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Project', new_project_path, id:"new" %>

<footer id="footer">Copyright 2014 Kira Banks</footer>

'

Nimir
  • 5,727
  • 1
  • 26
  • 34
  • This problem is likely due to either your form not linking to the correct route, or you not including the correct route in your routes.rb file. Can you show us your routes.rb and view file? – chopper draw lion4 Dec 07 '14 at 05:26

1 Answers1

1

To keep your application secured, Rails has a feature called Strong Parameters and the docs says:

It provides an interface for protecting attributes from end-user assignment. This makes Action Controller parameters forbidden to be used in Active Model mass assignment until they have been whitelisted.

So, basically you need to whitelist the new client attribute in the Projects controller by adding it to the list:

class ProjectsController < ApplicationController
# ...
# at the end of the file
private

    def project_params
      params.require(:project).permit(:title, :description, :hours, :done, :client)
    end
end 
Nimir
  • 5,727
  • 1
  • 26
  • 34
  • @GraphicMac glad it worked! please don't forget to mark the answer as correct using the green arrow under the votes count >> so future readers know it's a valid solution! – Nimir Dec 07 '14 at 06:27
  • Thanks for that as well haha, I'm new here. – GraphicMac Dec 07 '14 at 06:39