Forum: Ruby on Rails Database is not updating after the Active Record Migration.

F2e2d47a6d8a508dcd28c2aae8992dcd?d=identicon&s=25 Cameron D. (cameron_d)
on 2014-03-25 08:09
(Received via mailing list)
Hello.

I created a simple database to test adding a column in an active record
migration.  Using phpMyAdmin and ROR, this is the code I used for the
migration:

class AddColumns < ActiveRecord::Migration
  def self.up
      add_column :users, :need_it, :boolean
  end

  def self.down
      remove_column :users, :need_it
  end
end

the migration went successfully, as I can see the newly created column
in
phpMyAdmin.
The column is, trying to be, mapped to a checkbox, located in the
_form.html.erb file:

<%= form_for(@user) do |f| %>
....
...
...

<div class="field">
  <%= f. label :need_it &><br>
  <%= f.check_box :need_it %>
</div>

...
<% end %>

But when I enter a new user and select the checkbox, or edit a current
user's checkbox field, the new value doesn't show in the database
(MySQL).

What am I missing?

Thanks.
57733f1aef49b1201107b7fcf8c2ec53?d=identicon&s=25 Abdulsattar Mohammed (Guest)
on 2014-03-25 09:36
(Received via mailing list)
You probably didn't add :need_it to the strong parameters
(params.require(:users).permit(:need_it)) or if you're using Rails 3.x,
you
didn't add it to attr_accessible.


On Tue, Mar 25, 2014 at 2:20 AM, Cameron Diggs <vdogamer@gmail.com>
wrote:

>
> <%= form_for(@user) do |f| %>
> <% end %>
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/rubyonrails-talk...
> .
> For more options, visit https://groups.google.com/d/optout.
>



--
Regards,
Abdulsattar Mohammed
http://codingtales.com
4c6bde00168d595053c09aac7e487f8e?d=identicon&s=25 Colin Law (Guest)
on 2014-03-25 09:52
(Received via mailing list)
On 24 March 2014 20:50, Cameron Diggs <vdogamer@gmail.com> wrote:
>
> <%= form_for(@user) do |f| %>
> <% end %>
>
> But when I enter a new user and select the checkbox, or edit a current
> user's checkbox field, the new value doesn't show in the database (MySQL).

The first technique when looking for any bug is to determine the area
of code that is failing. Look in log/development.log and you will see
the parameters passed when you submit the form.  If the checkbox value
is not there then it is the view that is at fault, if the checkbox is
there then it is the controller code that is in error somewhere.

Colin
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.