Rails FormTagHelper missing important select and collection_select methods
-
23-09-2019 - |
문제
You can do this when you use form_for(@model...)
:
collection_select(:subscription, :duration, ["Some", "Values"], :to_s, :to_s, {:prompt => true})
And the output is something like this:
<select id="subscription_duration" name="subscription[duration]">
<option value="">Please select</option>
<option value="Some">Some</option>
<option value="Values">Values</option>
</select>
If you use a form without a model, you don't have that nice helper method to create the <option>
tags for you. Instead, you have to do this:
select_tag("subscription", '<option value="Some">Some</option><option value="Values">Values</option>')
FormHelper and FormOptionsHelper work together on a form wrapping a model, and they have the select
and collection_select
to make life easy. For a plain form_tag
(without a model), however, there is no such FormOptionsTagHelper. FormTagHelper has a select_tag
method, but you have to manually write out the options which is a waste. It seems like this has been fixed somewhere.
I could write my own helper to get rid of writing those option tags manually, but thats what FormOptionsHelper#collection_select
does... Is there an equivalent out there for forms without models?
해결책
SQLConnection을 사용하고 있기 때문에이 가정은 SQL Server 데이터베이스입니다.
가정을 감안할 때 MSDN 나는 정규 표현식에서 완전하고 완전한 초심자이지만, 나는 이것을 닫아야한다는 것을 발견했습니다 :
[\p{L}{\p{Nd}}$#_][\p{L}{\p{Nd}}@$#_]*
.
그러나 정규 표현식은 SQL Server 키워드를 해결하지 못하고 테이블 및 / 또는 열이 실제로 존재하는지 확인하지는 않지만 (귀하가 그 대부분의 문제가 아니라는 것은 아니지만).
이것이 제 응용 프로그램 이었으면 먼저 세미콜론이 포함 된 요청을 거부함으로써 최종 사용자가 주사를 수행하려고하지 않으려면
다음으로, 유효한 이름 구분 기호 ( ", ',', [,])를 제거하고 테이블 이름을 기간으로 분할하여 스키마가 지정되었는지 여부를 확인하고 information_schema.tables에 대한 쿼리를 실행하여 테이블 존재를 검증합니다. 테이블의 존재를 결정하기 위해
예 :
SELECT 1
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'tablename'
AND TABLE_SCHEMA = 'tableschema'
.
매개 변수를 사용 하여이 쿼리를 생성하면 주입으로부터 자신을 보호해야합니다.
마지막으로, INFORMATION_SCHEMA.COLUMNS 만 사용하여 테이블이 유효한 것으로 결정되면 열 (들)의 유효성을 결정함으로써 비슷한 단계 집합을 수행하여 각 열 이름의 존재를 검증 할 것입니다.
SQL Server 에서이 테이블의 유효한 열의 목록을 가져올 수있는 다음 각 요청 열이 내 코드 내의 목록에 있는지 확인합니다. 그런 식으로 어떤 열이 오류가 있는지 정확히 알 수 있고 사용자에게 피드백을 제공 할 수 있습니다.