新手问题 一个页面的下拉列表数据怎样从其他表字段获得,怎样做好,谢谢!

hirospeed · 2012年12月20日 · 最后由 hirospeed 回复于 2012年12月20日 · 2384 次阅读

A,B 表,新增 A 时页面有下列表,选择 B 中的记录,怎样把获取 B 的数据啊?A 是 A.all, B.all 就报错。 还有前台怎样赋值啊。

<%= f.label :t %>
<%= f.select :t ,@B.i%>

在 A 中有一个外键,是 B 的主键。

select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })

感觉大侠回复,我可能没有描述清楚,我也找了许多书,没有看到这样的例子,我再细说一下,请大侠们帮忙 我这有两个 controllers,一个是 tomcats_controller.rb,一个 machines_controller.rb tomcat 新增页面中有一个下拉列表,需要选择属于哪个 machines(machines 表) 这里我无法获取 machines 的表内容 def new @tomcat = Tomcat.new @ip=Tomcat.find_by_sql("select * from machines");######

respond_to do |format| format.html # new.html.erb format.json { render json: @tomcat } end end

这里也就无法赋值

<%= f.label :tomcat_status %>
<%= f.select :tomcat_status, ? %>
5 楼 已删除

请教, 1、如何动态将 tomct 日志显示到页面上 2、如何监控 tomcat 是否启动

谢谢大家帮忙解决

需要 登录 后方可回复, 如果你还没有账号请 注册新账号