Thanks Colin on reply. I tried with following code, which work good so just wanted to ask is this correct solution, for some reason i think this code "smell".
// routes.rbresources :entries, :only =>[:new, :create]
// user.rbclass User < ActiveRecord::Base
has_many :entries
end
// category.rbclass Category < ActiveRecord::Base
has_many :entries
end
// entry.rbclass Entry < ActiveRecord::Base
belongs_to :user
belongs_to :category
has_one :storage
accepts_nested_attributes_for :storage
end
// storage.rbclass Storage < ActiveRecord::Base
belongs_to :entry
has_one :vote
end
// vote.rbclass Vote < ActiveRecord::Base
belongs_to :storage
end
//
entries_controller.rbclass EntriesController < ApplicationController
def new
@entry = Entry.new(:user_id =>
current_user.id)
#Pass this to new.html.erb to use it like hidden field @entry.build_storage
end
def create
new_entry = Entry.new(params[:entry].permit(:user_id, :category_id, :storage_attributes => [:title, :content]))
new_entry.storage.build_vote
# Create new row in votes table new_entry.save
redirect_to root_url
end
end
// views/entries/new.html.erb<%= form_for @entry do | f | %>
<%= f.select :category_id, options_for_select([["slike", "1"], ["statusi", "2"]]) %>
<%=
f.hidden_field :user_id, :value => @entry.user_id %>
#Now pass this to create action <%= f.fields_for :storage do |storage| %>
<p>
<%= storage.label :title %><br>
<%= storage.text_field :title %>
</p>
<p>
<%= storage.label :content %><br>
<%= storage.text_area :content %>
</p>
<% end %>
<%= f.submit "Submit" %>
<% end %>