has many through - Rails How to an association and data at once -
i m newbie on rails have user , attachment model , has_many through relationships. want add data,it can more one, third model intermediate form when create attachment data. can save attachment data don't know how save data third model.here files
attachments/new.html.erb
<%= form_for(@attachment) |f| %> <div class="field"> <%= f.label :filename, "file name" %><br> <%= f.text_field :filename %> </div><br /> <div class="field"> <%= f.label :file, "file" %><br> <%= f.file_field :file %> </div> <br /> <div class="actions"> <%= f.submit "dosya yükle" %> </div> <% end %>
attachments_controller.rb
def new @attachment = attachment.new end def create @attachment = attachment.new(file_params) if @attachment.save redirect_to some_path else render action: 'new' end end
user.rb
has_many :interforms has_many :attachments, through: :interforms
attachment.rb
has_many :interforms has_many :users, through: :interforms
interform.rb
belongs_to :user belongs_to :attachment
my question how add data interform when add attachment
edit : didn't have routes interforms right now
Comments
Post a Comment