Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Nested Forms not showing up? Rails 4

nested form rails 4

  • Please log in to reply
3 replies to this topic

#1 Royceybaby

Royceybaby

    Passenger

  • Members
  • 2 posts

Posted 12 August 2014 - 12:27 PM

Disclaimer: I am a rails newbie!

 

Ok,

 

So I have been playing around designing an application using Rails 4. I haven't used Rails that much so all of this is quite new. (I have programming experience in C++)

 

I have been pulling my hair out trying to get nested forms working, I am sure I got nested forms working using Rails 3 and the railscasts demo last year, but Rails 4 is beating me.

 

Looking at the log, the query is being run to pull the data for the associated table, but nothing is rendered in the form.

 

I have read many web sites, but none have helped so far and I don't know where to start. The latest article I have followed is this http://www.createdby...ion-in-rails-4/

 

Still nothing being rendered in the view.

 

Where do I start debugging this, maybe my Rails install is broken?? But I am probably missing something crucial.

 

Thanks,

Royce



#2 Ohm

Ohm

    Driver

  • Moderators
  • 469 posts
  • LocationCopenhagen

Posted 12 August 2014 - 07:25 PM

Some code examples of what you've tried would be nice.  :)


Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk


#3 Royceybaby

Royceybaby

    Passenger

  • Members
  • 2 posts

Posted 12 August 2014 - 07:35 PM

Some code examples of what you've tried would be nice.  :)

 

Check out the link in the first post, I went back to basics and setup a new rails project using that example.Alternatively I have zipped up that project and put it on my dropbox https://dl.dropboxus...2/testforms.zip

 

Thanks,

Royce



#4 developerJohn

developerJohn

    Passenger

  • Members
  • 3 posts

Posted 08 December 2014 - 02:17 PM

I am having this same issue as well. My code is below. I get a 500 error on /tweaks/new

class Tweak < ActiveRecord::Base
  belongs_to :user
  has_many :tweak_versions
  accepts_nested_attributes_for :tweak_versions
end

class TweakVersion < ActiveRecord::Base
  belongs_to :tweak

  has_attached_file :file

  validates_attachment_content_type :file, :content_type => 'application/zip'
end

class TweaksController < ApplicationController

  def new
    @tweak = Tweak.new
    @tweak.user_id = session[:current_user_id]
    @tweak.tweak_versions.build
  end
end

<h1>Add a new Tweak</h1>
<% form_for @tweak do |tweak_form| %>
    <p>
      <%= tweak_form.label :name, 'Name:' %>
      <%= tweak_form.text_field :name %>
    </p>

    <p>
      <%= tweak_form.label :description, 'Description:' %>
      <%= tweak_form.text_area :description %>
    </p>

    <% tweak_form.fields_for :tweak_version do |version_form| %>
        <p><%= version_form.file_field :file %></p>
    <% end %>
    <p class='buttons'><%= tweak_form.submit 'Submit' %></p>

<% end %>

  • developerJohn likes this





Also tagged with one or more of these keywords: nested form, rails 4

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users