Proble wuth form

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: Permalink:
8: <%=h @encuesta.permalink %>
9:


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?

Hey,

Please refer to correct usage of form_for:
API:

with examples:
http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for

On Fri, Mar 13, 2009 at 1:21 PM, Jose vicente Ribera pellicer <
[email protected]> wrote:

<%- end -%>
Extracted source (around line #10):

Thanks & Regards,
Sumanth Krishna. A
+358 40 3276564

Blogs:
TwinclingCommunity:

http://www.twincling.org/node/227

http://yourway2health.blogspot.com/
http://www.osef.twincling.org

Sumanth Krishna wrote:

Hey,

Please refer to correct usage of form_for:
API:
ActionView::Helpers::FormHelper
with examples:
form_for (ActionView::Helpers::FormHelper) - APIdock

On Fri, Mar 13, 2009 at 1:21 PM, Jose vicente Ribera pellicer <
[email protected]> wrote:

<%- end -%>
Extracted source (around line #10):

Partially solved.

<%- end -%> was write, but i didń copy it.

Thanks a lot

I tried with:

form_for [@encuesta, @pregunta] do |f|
<%= f.error_messages %>

<%= f.label :texto %>
<%= f.text_field :texto %>

... end

The result is the same. I thinking that perhaps i can0t do “restful”
forms :frowning:

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 %>

<%= f.label :texto %>
<%= f.text_field :texto %>

... 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:


7: <%= f.label :texto %>

8: <%= f.text_field :texto %>
9:


10:


11: <%= f.label :encuesta_id %>

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??

Jose vicente Ribera pellicer wrote:

I tried with:

form_for [@encuesta, @pregunta] do |f|
<%= f.error_messages %>

<%= f.label :texto %>
<%= f.text_field :texto %>

... end

The result is the same. I thinking that perhaps i can0t do “restful”
forms :frowning:

Solved!!

<% form_for(@pregunta, :url => encuesta_preguntas_path(@encuesta)) do
|f| %>

It rules!!