无法在Ruby on Rails控制器中访问Multiselect值

时间:2017-08-10 04:37:34

标签: ruby-on-rails

我试图在Ruby on Rails中为多对多关系实现多选,但是我无法访问表示user_ids字段中所选用户ID的字符串数组。

点击更新后,以下是我的import os import numpy as np import pandas as pd from matplotlib.mlab import griddata from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt from matplotlib.colors import Normalize from shapely.geometry import mapping, Polygon, LineString,MultiLineString import fiona # set up plot plt.clf() fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, axisbg='w', frame_on=False) # grab data data = pd.read_csv('Filename.csv', sep=',') norm = Normalize() # define map extent lllon = -180 lllat = -90 urlon = 180 urlat = 90 # Set up Basemap instance m = Basemap(#projection = 'merc',llcrnrlon = lllon, llcrnrlat = lllat, urcrnrlon = urlon, urcrnrlat = urlat,resolution='h', epsg=4326) # transform lon / lat coordinates to map projection data['projected_lon'], data['projected_lat'] = m(*(data.CLON.values, data.CLAT.values)) # grid data numcols, numrows = 100, 100 xi = np.linspace(data['projected_lon'].min(), data['projected_lon'].max(), numcols) yi = np.linspace(data['projected_lat'].min(), data['projected_lat'].max(), numrows) xi, yi = np.meshgrid(xi, yi) # interpolate x, y, z = data['projected_lon'].values, data['projected_lat'].values, data.PRES.values zi = griddata(x, y, z, xi, yi) # contour plot cs = plt.contour(xi, yi, zi,zorder=4) plt.show() lenvar = (len(cs.collections)) #number of contours print(lenvar) #print(cs.collections) lines = [] # Empty list for contour sections for i in range(lenvar): n = i p = cs.collections[i].get_paths()[0] v = p.vertices # getting the individual verticies as a numpy.ndarray x = v[:,0] #takes first column y = v[:,1] #takes second column line = LineString([(i[0], i[1]) for i in zip(x,y)]) #Defines Linestring lines.append(line) #appends to list schema = {'geometry': 'LineString','properties': {'id': 'int'}} # sets up parameter for shapefile with fiona.open('ConShp.shp', 'w', 'ESRI Shapefile', schema) as c: # creates new file to be written to for j in range(len(lines)): l = (lines[j]) # creates variable print(l) print(type(l)) c.write({'geometry': mapping(l),'properties': {'id': j},})

project_params

以下是我的"project"=>{"name"=>"Project Name", "client"=>"Client X", "project_url"=>""}, "user_ids"=>["2", "3", "4", "5"], "commit"=>"Update Project", "id"=>"1"} 代码

ProjectsController

def update puts project_params[:user_ids=>[]] respond_to do |format| if @project.update(project_params) format.html { redirect_to @project, notice: 'Project was successfully updated.' } format.json { render :show, status: :ok, location: @project } else format.html { render :edit } format.json { render json: @project.errors, status: :unprocessable_entity } end end end def project_params params.require(:project).permit(:id, :name, :client, :project_url, :user_ids => []) end 行打印一个空白行。我还尝试了puts project_params[:user_ids=>[]]puts project_params[:user_ids] - 其中没有一项工作

以下是我的puts project_params[:user_ids[]]代码

_form.html.erb

1 个答案:

答案 0 :(得分:1)

select标签将使用第一个参数作为键。因此,值位于:

tableView.reloadSections(IndexSet(integer: indexPath.section),
                         with: UITableViewRowAnimation.fade)

或者如果您正在使用表单构建器

params[:user_ids]

然后它将在<%= form_for @project do |f| %> <%= f.select :user_ids, options_from_collection_for_select(User.all, "id", "name", @project.user), { :multiple => true, :size =>10} %> <% end %>

中提供