开发者

How can I input tags through a form (using acts_as_taggable_on) and Rails 3

开发者 https://www.devze.com 2023-02-26 19:51 出处:网络
Here is my form: 1 <%= semantic_form_for @vendor do |f| %> 2<% f.inputs do %> 3<%= f.input :name %>

Here is my form:

  1 <%= semantic_form_for @vendor do |f| %> 
  2     <% f.inputs do %> 
  3        <%= f.input :name %> 
开发者_如何学Go  4        <%= f.input :tag_list %>    
  5     <% end %> 
  6     <%= f.buttons %> 
  7 <% end %> 

Vendor.rb is acts_as_taggable_on.

However, when I enter strings into the field for tag_list, nothing gets stored when I go back into the console to check on vendor.tags.

What can I do to allow input of tags from a form?

 10   def new
 11     @vendor = Vendor.new
 12   end
 13   
 14   def create
 15     @vendor = Vendor.new(params[:vendor])
 16     if @vendor.save
 17       flash[:notice] = "Successfully created vendor."
 18       redirect_to @vendor
 19     else
 20       render :action => 'new'
 21     end
 22   end


Are you using attr_accessible in your model?

If yes, add :tag_list to it.

For Example:

attr_accessible :attr1, :tag_list

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号