Hi first at all sorry if mu english is not the best.
I have this models:
Encuesta->titulo and description are string. Encuesta has_many :preguntas Preguntas-> texto is string, encuesta_id and orden are integer. Pregunta belongs_to :encuesta and has_many :soluciones Soluciones-> texto is string, pregunta_id and orden are integer. Soluciones belongs_to :pregunta
Routes: map.resources :encuestas do |encuesta| map.resources :preguntas do |pregunta| pregunta.resources :solucions end end
I can create preguntas for encuestas. But in the index view of preguntas I have this code:
<%= link_to pregunta.texto, encuesta_pregunta_solucions_path(@encuesta, @pregunta) %></td>
If I choose one pregunta the url that shows firefox is like that:
http://localhost:3000/encuestas/1/preguntas//solucions
It doesn't show preguntas_id in the url
In another way if i write for example this url in firefox:
http://localhost:3000/encuestas/1/preguntas/1/solucions
It shows me this error: NoMethodError in SolucionsController#index
undefined method `find' for #<Encuesta:0x7f790aa4fdc8>
RAILS_ROOT: /home/jose/marzo Application Trace | Framework Trace | Full Trace
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:260:in `method_missing' app/controllers/solucions_controller.rb:94:in `find_encuesta_pregunta'
Parameters:
{"encuesta_id"=>"1", "pregunta_id"=>"1"}
My code-> Solucion controller
before_filter :find_encuesta_pregunta
def index
@solucions = @pregunta.solucions.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @solucions } end end
def find_encuesta_pregunta @encuesta=Encuesta.find(params[:encuesta_id]) @pregunta=@encuesta.find(params[:pregunta_id]) end
Anybody can help me?