I’m trying to have a simple webform in my administration section to
add a user. I have the text_fields for adding the user’s name,
password, and password confirmation, but cannot seem to figure out the
checkbox. I want it to be a single checkbox, that if clicked, will set
the database column “access” to be “admin” and if its unchecked, set
it to be “user”. This is what I have so far but nothing is rendering
just because of the check_box line.
<% form_for :user do |form| %>
<label for “user_name”>Name:
<%= form.text_field :name %>
It seems to think that :access is a method… its actually the name of
the column in the database. Is that wrong to put there? Do I need a
method there that assigns the database the value?
It seems to think that :access is a method… its actually the name of
the column in the database. Is that wrong to put there? Do I need a
method there that assigns the database the value?
Its supposed to… I say that because my original table did not
contain that field, but I added it with this migration:
class UserAccess < ActiveRecord::Migration
def self.up
add_column :users, :access, :string, :default => “user”
end
def self.down
remove_column :users, :access
end
end
I executed “rake db:migrate” but its still not showing up… Maybe my
problem was due to my migration not editing the table? Does it matter
that there is already data in the table?
I’d open up the db and make sure the field is there. Then restart the
web
server (just in case it didn’t pick up the db change).
The code you have should work… :access should be the method on the
object
bound to the form (user). If it’s burping at you, it’s probably that the
field isn’t there.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.