Hi, forst at all sorry if my english is not the best. I have a problem with a form. I use REST routes, encuestas has_many preguntas and preguntas belongs_to encuesta and has_many votados. I want to show in a form all the respuestas in one encuesta. I tried with this <%form_for [@encuesta, @preguntas] do |f|%> hola <%- end -%> But it doesn´t work. This is the error: RuntimeError in Encuestas#show Showing encuestas/show.html.erb where line #10 raised: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id Extracted source (around line #10): 7: <b>Permalink:</b> 8: <%=h @encuesta.permalink %> 9: </p> 10: <%form_for [@encuesta, @preguntas] do |f|%> 11: 12: hola 13: ------------------- If i try with something like this: <%for pregunta in @encuesta.preguntas %> hello <%end%> I can see hello so many times like preguntas are in encuesta. But i need a form_for. Anybody can help me please? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Hey, Please refer to correct usage of form_for: API: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html with examples: http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for On Fri, Mar 13, 2009 at 1:21 PM, Jose vicente Ribera pellicer < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, forst at all sorry if my english is not the best. I have a problem > with a form. I use REST routes, encuestas has_many preguntas and > preguntas belongs_to encuesta and has_many votados. > I want to show in a form all the respuestas in one encuesta. I tried > with this > > > <%form_for [@encuesta, @preguntas] do |f|%> > hola > <%- end -%> > > But it doesn´t work. This is the error: > > RuntimeError in Encuestas#show > > Showing encuestas/show.html.erb where line #10 raised: > > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > Extracted source (around line #10): > > 7: <b>Permalink:</b> > 8: <%=h @encuesta.permalink %> > 9: </p> > 10: <%form_for [@encuesta, @preguntas] do |f|%> > 11: > 12: hola > 13: > > ------------------- > > If i try with something like this: > <%for pregunta in @encuesta.preguntas %> > hello > <%end%> > I can see hello so many times like preguntas are in encuesta. But i need > a form_for. > > Anybody can help me please? > -- > Posted via http://www.ruby-forum.com/. > > > >-- -- Thanks & Regards, Sumanth Krishna. A +358 40 3276564 Blogs: TwinclingCommunity: http://sumanthtechsavvy.blogspot.com/ http://www.twincling.org/node/227 http://yourway2health.blogspot.com/ http://www.osef.twincling.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Sumanth Krishna wrote:> Hey, > > Please refer to correct usage of form_for: > API: > http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html > with examples: > http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for > > On Fri, Mar 13, 2009 at 1:21 PM, Jose vicente Ribera pellicer < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> <%- end -%> >> Extracted source (around line #10): >> >> >> > >> > > > --Partially solved. <%- end -%> was write, but i didń copy it. Thanks a lot -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Umm i have a problem. my routes.rb : map.resources :encuestas do |encuesta| encuesta.resources :preguntas do |pregunta| pregunta.resources :solucions end end I can see perfecly the index of preguntas Now I want to create a new pregunta. My url->http://localhost:3000/encuestas/1/preguntas/new In the preguntas''s controller: def index @encuesta = Encuesta.find(params[:encuesta_id]) @preguntas = Pregunta.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @preguntas } end In the view of new pregunta: form_for [@encuesta, @preguntas] do |f| <%= f.error_messages %> <p> <%= f.label :texto %><br /> <%= f.text_field :texto %> </p> ... end Encuesta has 2 fields, titulo and descripcion. Both are strings Pregunta has 3 fields, encusta_id and orden are integer and text is string. This is the error message: NoMethodError in Preguntas#new Showing app/views/preguntas/new.html.erb where line #8 raised: undefined method `texto'' for #<Encuesta:0x7ffe122c40a8> Extracted source (around line #8): 5: 6: <p> 7: <%= f.label :texto %><br /> 8: <%= f.text_field :texto %> 9: </p> 10: <p> 11: <%= f.label :encuesta_id %><br /> Encuesta doesn''t has texto, texto is a field of preguntas. This form is for preguntas not for encuesta. Why is supossing that texto is a field of encuesta?? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I tried with: form_for [@encuesta, @pregunta] do |f| <%= f.error_messages %> <p> <%= f.label :texto %><br /> <%= f.text_field :texto %> </p> ... end The result is the same. I thinking that perhaps i can0t do "restful" forms :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jose vicente Ribera pellicer wrote:> I tried with: > > form_for [@encuesta, @pregunta] do |f| > <%= f.error_messages %> > > <p> > <%= f.label :texto %><br /> > <%= f.text_field :texto %> > </p> > ... > end > > The result is the same. I thinking that perhaps i can0t do "restful" > forms :(Solved!! <% form_for(@pregunta, :url => encuesta_preguntas_path(@encuesta)) do |f| %> It rules!! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---