why strong parameters for the CREATE, but not NEW, in a rails controller? -
i confused why, in example articles controller, create method utilizing strong parameters, new method isn't?
def new @article = article.new end def create @article = article.new(article_param) if @article.save redirect_to @article else render "new" end end
because strong_parameters there whitelist params before update or create record. while on new
or edit
action there not action on db records, , isn't necessary whitelist params. on update
, create
controller actions there action on db, , parameters not whitelisted forbidden.
also rails guides show same definition: "with strong parameters, action controller parameters forbidden used in active model mass assignments until have been whitelisted. means you'll have make conscious choice attributes allow mass updating , prevent accidentally exposing shouldn't exposed."
the common example when: in browser can edit field name , change <input name=user[name] ...>
<input name=user[admin] ...>
@ form change value '1' , submit. without strong parameters user[:admin]
valid parameter , changed @ database. further, @ new
or edit
action, there no risk of impact on db, because sending form browser.
Comments
Post a Comment