ive got a problem with my database in that it only seems to be storing the id of new entries and displaying those in my form instead of the :name attribute that im asking for. If I view the entry either using my form or via a sqlite3 browser. Only the ID is showing.
Here’s my migration file..
class CreateClients < ActiveRecord::Migration
def change
create_table :clients do |t|
t.string :name
t.string :detail
t.string :more_detail
t.string :more_details
t.timestamps
end
end
end
My form..
<%= form_for @client, :html => { :class => 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :name, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :detail, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :detail, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :more_detail, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :more_detail, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :more_details, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :more_details, :class => 'text_field' %>
</div>
</div>
<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
clients_path, :class => 'btn' %>
</div>
<% end %>
And my view..
...
<% @client.each do |client| %>
<tr>
<td><%= link_to client.name, client_path(client) %></td>
<td>
...
Instead of showing the name (eg foo) and then a link to that clients details. It’s showing me /clients/3 and when I click on it, it’s taking me to a page with empty name annd detail’s fields even though they were specified when saving the entry.
If I use a sqlite3 browser. I can see the entrys have been saved but each has a null value for all columns except ID.
I think I know what your problem is. The latest Rails version has attribute protection from mass assignment by default, so you need to specify which attributes you want to be accessible from outside the model like this:
Read this section of the security guide.
P.S.: Did the console throw any errors when you are creating a new record?