Hi Javix,
thank you for the suggestions.
Now i have removed the use has_many:through association.
And i could able to upload stream into database.
But the problem here is:
while uploading data into other tables
1)i am not getting the transportstream_id from transportstreams in to the programs table.
2)throughing the error like:
ActiveRecord::StatementInvalid in Containerformats#show
Showing app/views/containerformats/show.html.erb where line #26 raised:
Mysql::Error: Unknown column 'programs.containerformat_id' in 'where clause': SELECT * FROM `programs` WHERE (`programs`.containerformat_id = 2)
but data is storing in the correspomding tables.
my code details;
in containerformatcontroller:
def new
@containerformat = Containerformat.new
@containerformat.transport_streams.build
@containerformat.programs.build
@containerformat.streams.build
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @containerformat }
end
end
--------in containerformat model
class Containerformat < ActiveRecord::Base
has_many :transport_streams
has_many :programs
has_many :streams
def transport_stream_attributes=(transport_stream_attributes)
transport_stream_attributes.each do |attributes|
transport_streams.build(attributes)
end
end
def program_attributes=(program_attributes)
program_attributes.each do |attributes|
programs.build(attributes)
end
end
def stream_attributes=(stream_attributes)
stream_attributes.each do |attributes|
streams.build(attributes)
end
end
end
---------------------in views(new.html.erb)<h1>New containerformat</h1>
<% form_for(@containerformat) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :stream_name %><br />
<%= f.text_field :stream_name %>
</p>
<p>
<%= f.label :location %><br />
<%= f.text_field :location %>
</p>
<p>
<%= f.label :containertype_id %><br />
<%= f.text_field :containertype_id %>
</p>
<%for transport_stream in @containerformat.transport_streams%>
<%fields_for "containerformat[transport_stream_attributes][]", transport_stream do |ts_form|%>
<p>Num_programs</p>
<p><%= ts_form.text_field :num_programs%></p>
<p>Encryption std</p>
<p><%= ts_form.text_field :encryption_std%></p>
<% end %>
<% end %>
<%for program in @containerformat.programs%>
<%fields_for "containerformat[program_attributes][]", program do |ts_form|%>
<p>PID</p>
<p><%= ts_form.text_field :pid%></p>
<% end %>
<% end %>
<%for stream in @containerformat.streams%>
<%fields_for "containerformat[stream_attributes][]", stream do |ts_form|%>
<p>videocodecid</p>
<p><%= ts_form.text_field :videoCodec_id%></p>
<p>audiocodecid</p>
<p><%= ts_form.text_field :audioCodec_id%></p>
<% end %>
<% end %>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
<%= link_to 'Back', containerformats_path %>
-------showpage
<p>
<b>Stream name:</b>
<%=h @containerformat.stream_name %>
</p>
<p>
<b>Location:</b>
<%=h @containerformat.location %>
</p>
<p>
<b>containertype_id:</b>
<%=h @containerformat.containertype_id %>
</p>
<%- @containerformat.transport_streams.each do |task| -%>
<p>
<b>Number of programs:</b>
<%= task.num_programs %>
</p>
<%- end -%>
<%- @containerformat.programs.each do |task| -%>
<p>
<b>PID:</b>
<%= task.pid %>
</p>
<%- end -%>
<%- @containerformat.streams.each do |task| -%>
<p>
<b>videoCodec_id:</b>
<%= task.videoCodec_id %>
<b>audiocodecid:</b>
<%= task.audioCodec_id %>
</p>
<%- end -%>
<%= link_to 'Edit', edit_containerformat_path(@containerformat) %> |
<%= link_to 'Back', containerformats_path %>
Can you tell me where i am doing the mistake?
Can you suggest me how to get the valus of other tables in the show page?
regards
Srikanth