Values stripped from form when submitted

19 views
Skip to first unread message

Martin Stabenfeldt

unread,
Sep 3, 2013, 6:32:22 AM9/3/13
to rubyonra...@googlegroups.com
Hi,

When I submit my form, the value form_id is empty, even though I could see it had a value when I inspected the HTML.
Any clue why it´s stripped? form_id is a virtual attribute on Feature
I´m running Rails 4


1 class Feature < ActiveRecord::Base
2   belongs_to :request
3   validates_presence_of :title
4   validates_presence_of :text
5   validates_presence_of :request_id
6 
7   attr_accessor :form_id
8 end

form.html.slim
 6 = simple_form_for([@request, @feature], remote: remote,
 7   html: {class: "form-inline new_feature feature#{n+1}" }) do |f|
 8   .border.padding10
 9     = f.error_notification
10 
11     .form-inputs
12       = f.hidden_field :request_id, :values => @request.id rescue nil
13       = f.hidden_field :form_id, :values => @request.id rescue nil



From console
  Processing by FeaturesController#create as JS
  Parameters: {"utf8"=>"✓", "feature"=>{"request_id"=>"", "form_id"=>"", "title"=>"sdf", "text"=>"sf"}, "commit"=>"Create Feature", "request_id"=>"43"}
  Rendered features/create.js.slim (0.1ms)
 Completed 200 OK in 21ms (Views: 3.6ms | ActiveRecord: 4.2ms)
 127.0.0.1 - - [03/Sep/2013 10:57:09] "POST /requests/43/features HTTP/1.1" 200 - 0.0560


FeaturesController
 1 class FeaturesController < ApplicationController
29   def create
30     @request = Request.find(params[:request_id])
31     @feature = Feature.new(feature_params)
32     @feature.request = @request
33 
34     respond_to do |format|
35       if @feature.save
36         format.html { redirect_to @feature, notice: 'Feature was successfully created.' }
37         #format.json { render action: 'show', status: :created, location: @feature }
38         format.js
39       else
40         format.html { render action: 'new' }
41         format.json { render json: @feature.errors, status: :unprocessable_entity }
42       end
43     end
44   end
78     def feature_params
79       params.require(:feature).permit(:request_id, :text, :title, :form_id)
80     end


Cheers,
Martins

Frederick Cheung

unread,
Sep 3, 2013, 8:53:35 AM9/3/13
to rubyonra...@googlegroups.com

On Tuesday, September 3, 2013 11:32:22 AM UTC+1, Martin Stabenfeldt wrote:

form.html.slim
 6 = simple_form_for([@request, @feature], remote: remote,
 7   html: {class: "form-inline new_feature feature#{n+1}" }) do |f|
 8   .border.padding10
 9     = f.error_notification
10 
11     .form-inputs
12       = f.hidden_field :request_id, :values => @request.id rescue nil
13       = f.hidden_field :form_id, :values => @request.id rescue nil


 That should be :value, not :values
 
Fred 

Martin Stabenfeldt

unread,
Sep 3, 2013, 9:47:06 AM9/3/13
to rubyonra...@googlegroups.com
Woops, thanks Fred! :-)
Reply all
Reply to author
Forward
0 new messages