UrlCommand 모델에 cgi_attributes
hstore 유형 열이 있습니다.레일 4 동적으로 Hstore 키를 생성하고 자동으로 허용 목록에 추가합니다.
class UrlCommand < ActiveRecord::Base
store_accessor :cgi_attributes, :name, :range, :security, :default_value
end
그러나 cgi_attributes
의 키는 사용자가 동적으로 추가해야합니다.
그리고 나는 또한 하드 코딩보다
오히려 내 양식에 제기 한 입력으로 각 키의 열
- [:name, :range, :security].each do | column |
= render :partial => 'attributes' , :locals => { f: f, column: column }
을 렌더링 할 또한으로 그 동적으로 생성 된 키를 갱신 할 수 있습니다 추가 할 필요가 내 모델. 이제
def url_command_params
params.require(:url_command).permit(:model_name, :firmware_version, :cgi_attributes,
:cgi_name,:name, :range, :security)
end
, 내 모든 코드는 어떻게 키를 만드는 방법과 값이 동적으로 UrlCommand 모델에 사용자가 추가 및 저장할 수있는 하드 코드를 기반으로?
가능한 중복 http://stackoverflow.com/questions/17348703/rails-4-strong-params-dynamic-hstore-keys – Monideep
@deep ActiveRecord를 통해 해당 키에 액세스하는 방법은 언급하지 않습니다. – newBike
나는 같은 문제가있다. store_accessor를 동적으로 변경해야하며 해당 hstore 데이터를 표시/저장하는 방법 – parzival