Hi Mark,
Thanks a lot… setting @sac_table_platform.platform_code = ‘ORA’ worked
for the default case, but it created a new problem for me: now when I
tried to specifically select a value (eg, ‘NSK’) from the
collection_select, it didn’t. Instead, it always selected ‘ORA’. I tried
to include a blank in the list, and put an if-condition in the
controller, but now it gets a null for ‘platform_code’.
Could you please tell me what I am doing wrong?
The relevant snippets are here:
In the controller:
def new
@create_date = @last_modify_date = getdate()
end
def create
…
params[:sac_table_platform][:table_id] =
params[:sac_table_config][:table_id]
params[:sac_table_platform][:table_config_id] =
params[:sac_table_config][:table_config_id]
@sac_table_platform =
SacTablePlatform.new(params[:sac_table_platform])
if params[:sac_table_platform][:platform_code].nil?
@sac_table_platform.platform_code = ‘ORA’
end
if @sac_table_config.save and @sac_table_platform.save
flash[:message] = { :title => ‘Information’, :msg => ‘SAC Table
Config and SAC Table Platform are successfully created.’ }
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end
In the ‘new.rhtml’ view:
<%= collection_select (“sac_table_platform”, “platform_code”,
Platform.find(:all, :order => “platform_code”),
:platform_code, :platform_code, :include_blank => true ) %>
Error I got:
OCIError: ORA-01400: cannot insert NULL into
(“SAC_CFG”.“SAC_TABLE_PLATFORM”.“PLATFORM_CODE”): INSERT INTO
SAC_Table_Platform (table_name, table_id, table_config_id,
platform_code) VALUES (’’, 6140, 1, ‘’)
Parameters: {“name”=>“add_form”, “commit”=>“Create”,
“sac_table_platform”=>{“platform_code”=>"", “table_id”=>“6140”,
“table_name”=>"", “table_config_id”=>[#<SacTableConfig:0x4b16260
@attributes={“nextval”=>59.0}>]},
“sac_table_config”=>{“last_modify_date”=>#<Date: 4908771/2, 0, 2299161>,
“table_id”=>“6140”, “create_date”=>#<Date: 4908771/2, 0, 2299161>,
“change_description”=>“aswq”,
“table_config_id”=>[#<SacTableConfig:0x4b16260
@attributes={“nextval”=>59.0}>]}}
Thanks a lot again.
Mark Reginald J. wrote:
Niaz Arifin wrote:
:platform_code, :platform_code, { :selected => @selected } %>
Arif, just set @sac_table_platform.platform_code = ‘ORA’, either in
your controller or in Platform.initialize
- How can I build my own list of collection_select, e.g., a list of
three people, say, to show [Adam, Bob, Charley] on the collection_select
for the corresponding values [‘A’, ‘B’, ‘C’] in a table (which already
exists), and use it in my view?
Just use an ordinary select having options parameter
[[‘Adam’,‘A’], [‘Bob’,‘B’], [‘Charley’,‘C’]]
–
We develop, watch us RoR, in numbers too big to ignore.