Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails 4.2 text_field issue #620

Closed
ghost opened this issue Dec 24, 2014 · 12 comments
Closed

rails 4.2 text_field issue #620

ghost opened this issue Dec 24, 2014 · 12 comments

Comments

@ghost
Copy link

ghost commented Dec 24, 2014

Hi. I'm using ruby 2.1.5 and recently upgraded to rails 4.2. I noticed ActionView::Helpers::Tags::TextField no longer calls html_safe on its value, which means that for a post with tag_list ['ruby', 'rails'], the following erb block
<%= f.text_field :tag_list %>
produces
<input type="text" value="ruby rails" name="post[tag_list]" id="post_tag_list">
rather than
<input type="text" value="ruby, rails" name="post[tag_list]" id="post_tag_list">

It's easily fixed by
<%= f.text_field :tag_list, value: @post.tag_list.to_s %>
but I was wondering if there's a way to go about this issue without having to specify the value option each time?

@seuros
Copy link
Collaborator

seuros commented Dec 24, 2014

Yes, this is by design for security reasons.
But we could add an option to html safe the tags by default.

@DaniG2k
Copy link

DaniG2k commented Dec 25, 2014

It would be nice, yes. Right now I am also forced to do:

<%= f.label tag.to_s.titleize %>
<% tag_sym = "#{tag.to_s.singularize}_list".to_sym %>
<% tag_list = "#{tag.to_s.singularize}_list" %>
<%= f.text_field tag_sym, value: @article.send(tag_list).to_s, :placeholder => "Comma-separated list of #{tag.to_s}", class: 'form-control' %>

Note: I asked this on StackOverflow as well 😦

@bf4
Copy link
Collaborator

bf4 commented Dec 25, 2014

The best option might be to make a custom input for the form builder

@ghost
Copy link
Author

ghost commented Dec 27, 2014

Seems like the easiest way is to make a custom tag_list_field where the input type defaults to text or can be specified. Thanks for the help!

@ghost ghost closed this as completed Dec 27, 2014
@lenart
Copy link

lenart commented Jan 21, 2015

Not being able to use Rails' form helpers "out of the box" feels a bit weird to me as well.

Could @seuros or @bf4 explain why you decided to take this approach? You mentioned security but I'd like to understand this better.

jgarber623 added a commit to FrancisCMS/FrancisCMS that referenced this issue Jan 23, 2015
@stiff
Copy link
Contributor

stiff commented Feb 13, 2015

Maybe just add glued_tags and glued_tags= to use in forms?

@openscript
Copy link

What kind of security feature are you talking about?

@tirdadc
Copy link

tirdadc commented May 11, 2015

Why was this closed when no explanation for this change was provided?

@ScotterC
Copy link

This should be noted in a changelog somewhere because on upgrade to 4.2 I had some production projects lose tag data because when the resources were saved again the commas were lost and it created new tags.

@AlexVPopov
Copy link
Contributor

Created a wiki-page, addressing this issue.

@carlflor
Copy link

For simple_form it's like this:

<%= f.input :tag_list, input_html: {value: @something.tag_list.to_s} %>

@korny
Copy link

korny commented Jan 12, 2018

This was our solution:

module ActionView::Helpers::TagHelper
  private
  def tag_option_with_tag_list_support(key, value, escape)
    if value.is_a?(ActsAsTaggableOn::TagList)
      value = escape ? ERB::Util.unwrapped_html_escape(value) : value.to_s
    end

    tag_option_without_tag_list_support key, value, escape
  end
  alias_method_chain :tag_option, :tag_list_support
end

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests