rails code works in console not in controller -



rails code works in console not in controller -

i've been looking few days not can't find what's going on. i've got code when tested in rails console works well, in controller refuses create database entries.

the models utilize are:

class project < activerecord::base attr_accessible :name, :user_id belongs_to :user has_many :active_data_sets has_many :data_sets, :through => :active_data_sets end class dataset < activerecord::base attr_accessible :name, :project_id, :filename, :tempfilename has_many :active_data_sets has_many :projects, :through => :active_data_sets end class activedataset < activerecord::base attr_accessible :active, :data_set_id, :project_id belongs_to :project belongs_to :dataset end

i'm using form_tag in view because @ later stage want upload file, not part of model. found out form_tag won't work @ point. calling url form is:

http://localhost:3000/data_sets/new?project_id=1

and view:

<h1>datasets#new</h1> <p>find me in app/views/data_sets/new.html.erb</p> <%= form_tag import_data_sets_path %> <%= hidden_field_tag 'project_id', params[:project_id] %> <p> dataset name: <%= text_field_tag :name %> </p> <p> <%= submit_tag "create dataset" %> </p> <% end %>

in create method of controller have next code

def create @dataset = dataset.new @dataset.active_data_sets.build(:project_id => params[:project_id].to_i) @dataset.name = params[:name] @dataset.save end

which doesn't result in entries beingness made in database when come in next code in rails console endup right entries in database:

dataset = dataset.new dataset.active_data_sets.build(:project_id => 1) dataset.name = 'name' dataset.save

i thought hidden_field_tag returned info strings, why added .to_i, didn't seem trick either.

hopefully sees issue don't.

thanks reading.

ruby-on-rails rails-activerecord

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -