I have two models: Post and Tag. The Post model has an attr_accessor called :tag_name and the Tag model has an attribute called :name.
I have this form:
<%= form_for(@post) do |f| %>
<%= render 'shared/error_messages' %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.cktext_area :content %>
</div>
<div class="field">
<%= f.label :tag_name %>
<%= f.autocomplete_field :tag_name, autocomplete_tag_name_posts_path, :"data-delimiter" => ' ' %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
This is the output of the field:
<input data-autocomplete="/posts/autocomplete_tag_name" data-delimiter=" " id="post_tag_name" name="post[tag_name]" size="30" type="text">
I want the user to see the name of the tags as soon as they enter the show view.
Any suggestions of how to accomplish this?
EDIT:
I tried putting this at the end of the form:
<script type="text/javascript">
$('#post_tag_name').val($('#post_tag_name').val() + <%= render @post.tags %>);
</script>
But nothing happens
1 Answer