我在方法控制器中有这个渲染:
render :json => @boats,:include => {:port => {:only => [:id,:name],:include => {:city => {:only => [:id,:methods => :translatedCity}}}}
但是模型中的translatedCity方法应该接受语言参数.
def translatedCity language = params[:language] puts "translatedCity.language=" + language city = TranslationService.translateCity(self.city_id,language) return city.element_translation end
我在控制器中有参数.有没有办法将此参数传递给模型中的方法?
解决方法
所有答案都很好!
我刚做了类似的事情:
在控制器中:
boat.port.language = params[:language]
在模型中:
attr_accessor :language @language def translatedCity city = TranslationService.translateCity(self.city_id,language) return city.element_translation end
你怎么看?