GraphicMac
GraphicMac

Reputation: 3

How Do I Get an Modified Column from a Rails Scaffold to Hold Information as the others?

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>

'

Upvotes: 0

Views: 52

Answers (1)

Nimir
Nimir

Reputation: 5839

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 

Upvotes: 1

Related Questions