Hi,all. I''m new bee to Rails and I have trouble about fields_for
method..
It isn''t show up between the <%= f.fields ~ <% end %>
Please teach me some advice.
Thanks!
#new/_form.html.erb
<%= form_for(@user) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<!-- Below the code doesn''t show up.(<%= f.fields ... <% end
%>) -->
<%= f.fields_for :entry do |entry_form| %>
Title:<br/>
<%= entry_form.text_field :title %>
<% end %>
<br/>
<%= f.submit "Create" %>
<% end %>
# user.rb
class Entry < ActiveRecord::Base
belongs_to :user
end
# entry.rb
class User < ActiveRecord::Base
has_many :entries
accepts_nested_attributes_for :entries
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
You can''t refer entries as entry in your form. I think you want a has_one relationship between user and entry. On Mon, Jul 25, 2011 at 1:07 PM, harashin <haradashinya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi,all. I''m new bee to Rails and I have trouble about fields_for > method.. > It isn''t show up between the <%= f.fields ~ <% end %> > > Please teach me some advice. > Thanks! > > #new/_form.html.erb > <%= form_for(@user) do |f| %> > > <div class="field"> > <%= f.label :name %><br /> > <%= f.text_field :name %> > </div> > > <!-- Below the code doesn''t show up.(<%= f.fields ... <% end %>) --> > > <%= f.fields_for :entry do |entry_form| %> > > Title:<br/> > <%= entry_form.text_field :title %> > > > <% end %> > <br/> > <%= f.submit "Create" %> > <% end %> > > # user.rb > > class Entry < ActiveRecord::Base > belongs_to :user > end > > # entry.rb > > class User < ActiveRecord::Base > has_many :entries > accepts_nested_attributes_for :entries > > end > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 July 2011 10:07, harashin <haradashinya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi,all. I''m new bee to Rails and I have trouble about fields_for > method.. > It isn''t show up between the <%= f.fields ~ <% end %> > > Please teach me some advice. > Thanks! > > #new/_form.html.erb > <%= form_for(@user) do |f| %> > > <div class="field"> > <%= f.label :name %><br /> > <%= f.text_field :name %> > </div> > > <!-- Below the code doesn''t show up.(<%= f.fields ... <% end %>) --> > > <%= f.fields_for :entry do |entry_form| %><%= f.fields_for :entries do |entry_form| %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 July 2011 11:39, Sameer Rafiq <sameer.rafiq-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can''t refer entries as entry in your form. I think you want a > has_one relationship between user and entry.if user has_many entries then in the form you can do fields_for :entries -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Maruo,Sammer! I edit the entry to entries. And I add new Action to> @post.tags buildthen it worked fine! But I don''t know @post.tags.build mean. Please teach me about this mean? #post_controller.rb> def new > @post = Post.new > @post.tags.buildtags is table name. table name : tags table columns *tag_name tnanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- fields_for with accepts_nested_attributes: how to pass a value to a label
- Getting the object in fields_for
- Am I wrong or is fields_for not working right in Rails 2.2.2
- fields_for weirdness
- names of select elements inside a fields_for block not generated as expected