开发者

Rails CouchDB related models not seing each other

开发者 https://www.devze.com 2023-02-11 18:54 出处:网络
Having this code : Models paciente.rb class Paciente include SimplyStored::Couch has_many :consultas end consulta.rb

Having this code :

Models

paciente.rb

class Paciente
  include SimplyStored::Couch
    has_many :consultas
end

consulta.rb

class Consulta
  include SimplyStored::Couch
    belongs_to :paciente 
end

Controllers

consultas_controller.rb

class ConsultasController < ActionController::Base
  layout "application"
    before_filter :get_paciente
    def get_paciente
        @paciente = Paciente.find(params[:paciente_id])
    end
  def index
    @c开发者_开发知识库onsultas = @paciente.consultas.all
  end
    def new
        @consulta = @paciente.consultas.new
    end
  def create
    @consulta = Consulta.create(params[:consulta]) 
    if @consulta.save
      redirect_to(@consulta, :notice => 'Consulta was successfully created.')
    else
      render :action => "new"
    end
  end
end

Routes

routes.rb

Example::Application.routes.draw do
    resources :pacientes do
        resources :consultas
    end
end

Error

I can't list consultas like this.

/pacientes/very long paciente id couchdb style id/consultas

I can see @paciente object exists,(I can inspect it), but i can't reach consultas from there.

Because I get:

NameError in ConsultasController#index
uninitialized constant Consultum

on this line :

@paciente.consultas.all <-- I am unable to reach consultas

Last couple of days been over and over this, btw I am using the SymplyStored for accessing CouchDb; I have already tried specifying the class name but samee result and the class name is the same name as the relationship.

Thanks in Advance for any clues !


Salvador - Rails makes certain assumptions about the pluralization rules, namely that they are in English. While I am not very familiar with the couchDB api in Rails, it appears from the NameError that Rails is attempting to pluralize Consultas -> Consultum.

This is a blog post about another developer's experiences related to non-English model names and ActiveRecord ... chances are, you're running against the same thing in ActiveModel -> SimplyStored::Couch

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号