I have followed this Rails 4 Unpermitted Parameters for Array but it doesn't work for me. Here's my model
class Building
include Mongoid::Document
include Mongoid::Spacial::Document
field :address, :type => String
field :location, :type => Array, spacial: {lng: :longitude, lat: :latitude, return_array: true }
end
in controller
def update
ret = building_params.has_key?(:address) ? building_address_path(@building) : edit_building_path(@building)
respond_to do |format|
if @building.update(building_params)
format.html { redirect_to ret, notice: 'Building was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @building.errors, status: :unprocessable_entity }
end
end
end
def building_params
params.require(:building).permit(:address, :location => [])
end
html form
<input id="building_location" name="building[location]" type="text" value="[112.70665740967, -7.26961135864]" />
server log
Started PATCH "/id/buildings/52fb014862696b06ad100000" for 192.168.12.211 at 2014-02-13 14:08:24 +0700
Processing by BuildingsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"j/n8Sv1CmEf5LKQMjNb7iQndJjDzWqkxsGrVIdS6i54=", "building"=>{"location"=>"[112.75631079999994,-7.272195699999999]", "address"=>"Jalan Dharmawangsa"}, "commit"=>"Simpan", "locale"=>"id", "id"=>"52fb014862696b06ad100000"}
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} runtime: 6.4688ms
MOPED: 127.0.0.1:27017 QUERY database=development collection=buildings selector={"_id"=>BSON::ObjectId('52fb014862696b06ad100000')} flags=[] limit=0 skip=0 batch_size=nil fields=nil runtime: 8.3167ms
MOPED: 127.0.0.1:27017 QUERY database=development collection=users selector={"$query"=>{"_id"=>BSON::ObjectId('52fb013b62696b06ad000000')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 9.1527ms
Unpermitted parameters: location
default_url_options is passed options: {}
Unpermitted parameters: location
Redirected to http://bikinibottom:3000/id/buildings/52fb014862696b06ad100000/address
Completed 302 Found in 1280ms
EDIT:
I add this to Model
def location=( loc )
location = eval(loc)
end
there's no error at all but the location isn't saved