formtastic - how to prepopulate a string input with a value

后端 未结 2 964
甜味超标
甜味超标 2020-12-28 13:46

I\'m building an app, where users can give comments by just leaving their email to the comment.

I want them to be able to register directly from there, by a link wit

相关标签:
2条回答
  • 2020-12-28 14:08

    Yup, you got the right answer all by yourself! Formtastic's rdoc is a mess, but we're working on it. Another option if you want this purely at a view level is to use the :input_html option, which gives you direct access to HTML attributes of the input tag:

    f.input :email, :input_html => { :value => params[:email] }
    
    0 讨论(0)
  • 2020-12-28 14:33

    sometimes the easiest things come to your mind by asking for them:

    approach: do the job in the controller not the view!

    if params[:email]
      @user = User.new(:email => params[:email])
    else
      @user = User.new
    end
    

    sorry for bothering you!

    0 讨论(0)
提交回复
热议问题