http://www.example.com/users/sign_up?user[company_name]=Foo&user[region]=NA
我们的注册表包含接受公司名称和地区的字段.哪个可以根据注册链接预先填写.
这应该在实践中起作用,但它不是由于注册#new动作的实现方式. new *** 作使用空哈希调用build_resource方法.
def new resource = build_resource({}) respond_with resourceend
当输入为非零时,build_resource方法忽略resource_params.
def build_resource(hash=nil) hash ||= resource_params || {} self.resource = resource_class.new_with_session(hash,session)end
我不得不在我的注册控制器中超越新动作来克服这个问题.我不喜欢我的解决方案,因为它很脆弱.
def new resource = build_resource respond_with resourceend
是否有理由使用空哈希调用新 *** 作?是否可以使用空哈希调用(如在创建 *** 作中)?
解决方法 我最终覆盖了build_resource并将更改范围限定为新 *** 作.def build_resource(hash=nil) # scope the change to new actions return super unless action_name == "new" super.tap do |user| user.company_name = params[:user][:company_name] user.region = params[:user][:region] endend总结
以上是内存溢出为你收集整理的ruby-on-rails – 设计:能够将参数传递给注册#sign_up动作全部内容,希望文章能够帮你解决ruby-on-rails – 设计:能够将参数传递给注册#sign_up动作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)