About dynamic select

I want to design a dynamic select container.That is :when a user selects
a province,there is a city select container dropping out.Then when a
user select a
city,there is a city section container dropping out.I use the
observe_field to manage these.
1 controller:
def register
@user=User.new(params[:user])
if params[:user]&&@user.save
session[:login][email protected]
flash[:register]="#{@user.name}已创建"
redirect_to :action=>“upanel”
else
render :action=>“register”
end
end
def get_region_kind
@user=User.new
if params[:region_kind]==“省”
render(:template=>“login/province”)
elsif params[:region_kind]==“直辖市”
render(:template=>“login/direct_city”)
elsif params[:region_kind]==“特别行政区”
render(:template=>“login/special_area”)
end
end
def get_capital
@user=User.new
capital_select=params[:capital_select]
case capital_select
when “石家庄” then @section=User::SHIJIAZHUANG
when “秦皇岛” then @section=User::QINGHUANGDAO

end
end
2 view:
register.rhtml
<%form_for :user,:url=>{:action=>“register”},:html=>{:multipart=>true}
do |f|-%>

照片 <%=f.file_field "file"-%>图片名称使用中文以外字符

行政区划类别 <%=select_tag "regionalism",options_for_select(["请选择","省","直辖市","特别行政区"])-%>

<%=observe_field "regionalism",:update=>"region",:url=>{:action=>"get_region_kind"},:with=>"region_kind"-%>
<%=submit_tag "提交",:disable_with=>"请稍候..."-%> <%end-%>

province.rhtml

省 <%=select "user","province",User::PROVINCE-%>

市 <%=select "user","city",User::CAPITAL-%>

<%=observe_field "user_city",:update=>"user_section",:url=>{:action=>"get_capital"},:with=>"capital_select"-%>

区 <%=select "user","section",User::SHIJIAZHUANG-%>

get_capital.rhtml
<%=select “user”,“section”,@section-%>

Now,when i select province,the codes work.But when select the city,there
is blank city section select container.It is blank and not what i want.I
think the model should be right.so where is wrong? We can not use the
several user objects in the register.rhtml file to register an user? Or
there is another way to manage my question.

On Jul 20, 2:59 pm, Guo Y. [email protected]
wrote:

<%=observe_field
“user_city”,:update=>“user_section”,:url=>{:action=>“get_capital”},:with=>" capital_select"-%>

Çø <%=select "user","section",User::SHIJIAZHUANG-%>

get_capital.rhtml
<%=select “user”,“section”,@section-%>

Think about what’s going to happen here: the inside of user_section
will get replaced by what’s rendered.
So you’ll end up with
<select id=“user_section” …>
<select id=“user_section” …>


which doesn’t look good.

Fred

Thank you Frederick C…I did not pay attention to replacing the
inner html.
Thank you very much!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs