【发布时间】:2012-03-01 22:37:06
【问题描述】:
所以我正在尝试为注册用户构建一个向导。 我不能使用 javascript (我发现的是这种形式的通用解决方案。) 原因是我的向导中的每个页面都依赖于大量的 Javascript,这意味着一次加载需要很长时间。 哦,向导处理 3 种不同的资源。
我尝试了一种方法,但我目前一直坚持,坦率地说感觉不对。
(旁注:用户通过“体面曝光”gem 曝光)
这是我的向导控制器:
def index
case current_step
when 'description'
render 'users/edit'
when 'contact'
render 'contact_informations/edit'
when 'location'
render 'location/edit'
end
end
def current_step
@current_step || STEPS.first
end
def next_step
@current_step = STEPS[STEPS.index(current_step)+1]
index
end
def previous_step
@current_step = STEPS[STEPS.index(current_step)-1]
index
end
def final_step
@current_step == STEPS.last
end
然后我对每个资源都有一个更新操作(这是同一个向导控制器)
def update_description
if user.update_attributes(params[:user])
next_step
else
redirect_to user_wizard_path(user)
end
end
def update_contact_information
# Do stuff here
end
def update_location
# Do stuff here
end
从同一个控制器中调用操作似乎存在问题。 并且基于我以前从未见过这样做,感觉不对。
我想简单地完成什么: 我不想弄乱原始的资源 REST 控制器。 我希望每一步都得到验证 如果 update_attributes 失败,则重新渲染有错误的表单。 如果 update_attributes 成功渲染下一步。
我得出的结论是,我在这方面的尝试是行不通的,并且感觉不像是做事的“轨道方式”。 我看过 Ryan Bates 关于“多步形式”的 railscast,但即使在那之后,我似乎也无法弄清楚这一点。
【问题讨论】:
标签: ruby-on-rails forms wizard