pulling information from specific fields in Rails 4 Form -
i creating blog post versioning system. (i tried paper_trail , draftsman , don't have need). when user edits "live" page, instead of changing live version, app makes postversion table entry new information , calls "pending". however, if user edits "draft" page, no "pending" postversion created, edits page directly.
i can't seem form params pass form postversion.create! method. submits nil values when i'm trying pull form values.
posts_controller.rb
def update @post = post.find(params[:id]) if @post.status == 'draft' #this not important end if @post.status == 'live' @pending_post = postversion.create!(title: params[:title], status: 'pending', body: params[:body], post_id: @post.id ) end end
_form.html.slim
= simple_form_for [:admin, @post ], multipart: true |f| = f.error_notification = f.input :title, label: 'title', required: true, focus: true #rest of form redacted
the actual params may nested under "post" array of sorts, such post[title]
. might want define specific params method so:
def update @post = post.find(params[:id]) if @post.status == 'draft' #this not important end if @post.status == 'live' @pending_post = postversion.create!(title: post_params[:title], status: 'pending', body: post_params[:body], post_id: @post.id ) end end private def post_params params.require(:post).permit :title, :body end
Comments
Post a Comment