Ruby on Rails
Tuesday, September 3, 2013
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
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0cacabe2-29e8-4e33-913c-ca751554d3ed%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment