Why am I encountering this situation?
I''m using the following code in my article form:
<% form_for [:admin, @article] do |f| %>
<%= f.error_messages %>
<p>
<%= f.label "Tags" %><br />
<%= select_tag "tags", "<option>Value
1</option><option>Value
2</option><option>Value 3</option><option>Value
4</option><option>Value
5</option><option>Value 6</option>" %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>
When I raise raise params[:tags].to_yaml in my controller''s update
action, it prints the name of the tag.
For what reason would this value not be saved into the database?
I''m using acts_as_taggable_on :tags in my Article model.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 29, 3:53 pm, Pale Horse <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Why am I encountering this situation? > > I''m using the following code in my article form: > > <% form_for [:admin, @article] do |f| %> > > <%= f.error_messages %> > > <p> > <%= f.label "Tags" %><br /> > <%= select_tag "tags", "<option>Value 1</option><option>Value > 2</option><option>Value 3</option><option>Value 4</option><option>Value > 5</option><option>Value 6</option>" %> > </p> > > <p><%= f.submit "Submit" %></p> > > <% end %> > > When I raise raise params[:tags].to_yaml in my controller''s update > action, it prints the name of the tag. > > For what reason would this value not be saved into the database? >> I''m using acts_as_taggable_on :tags in my Article model. > --any attr_accessible/attr_protected calls in your model? Fred> Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jul 29, 3:53�pm, Pale Horse <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> � � <%= select_tag "tags", "<option>Value 1</option><option>Value >> >> For what reason would this value not be saved into the database? >> > >> I''m using acts_as_taggable_on :tags in my Article model. >> -- > > any attr_accessible/attr_protected calls in your model? > > FredI''ve already checked, there are none. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Could it be that your template should say <%= f.select "tags", ... %> and not <%= select_tag "tags", ... %> Stephan -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Stephan Wehner wrote:> > Could it be that your template should say > > <%= f.select "tags", ... %> > > and not > > <%= select_tag "tags", ... %> > > > StephanAgain, I''ve already checked. That was a desperate attempt by me as I knew it shouldn''t have any effect. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pale Horse wrote:> Stephan Wehner wrote: >> >> Could it be that your template should say >> >> <%= f.select "tags", ... %> >> >> and not >> >> <%= select_tag "tags", ... %> >> >> >> Stephan > > Again, I''ve already checked. That was a desperate attempt by me as I > knew it shouldn''t have any effect.Oh ok, then what is the controller code? Stephan -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Stephan Wehner wrote:> Pale Horse wrote: >> Stephan Wehner wrote: >>> >>> Could it be that your template should say >>> >>> <%= f.select "tags", ... %> >>> >>> and not >>> >>> <%= select_tag "tags", ... %> >>> >>> >>> Stephan >> >> Again, I''ve already checked. That was a desperate attempt by me as I >> knew it shouldn''t have any effect. > > Oh ok, then what is the controller code? > > StephanNothing short of what should be there, nothing more: def new @article = Article.new end def create @article = Article.new(params[:article]) if @article.save flash[:notice] = "Successfully created article." redirect_to admin_articles_path else render :action => ''new'' end end def edit @article = Article.find(params[:id]) end def update @article = Article.find(params[:id]) if @article.update_attributes(params[:article]) flash[:notice] = "Successfully updated article." redirect_to admin_articles_path else render :action => ''edit'' end end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 30, 9:15 am, Pale Horse <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > > <%= f.select "tags", ... %> > > > and not > > > <%= select_tag "tags", ... %> > > > Stephan > > Again, I''ve already checked. That was a desperate attempt by me as I > knew it shouldn''t have any effect.select_tag "tags" definitely won''t work though. What''s the view code you''re actually working with? What do the params look at the point they hit your controller ? And what''s in your model - it''s the one thing you haven''t shown so far. Fred> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> > On Jul 30, 9:15�am, Pale Horse <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> knew it shouldn''t have any effect. > select_tag "tags" definitely won''t work though.Indeed, you''re right. I made the change to: select_tag "article[tags]"> What''s the view code > you''re actually working with? What do the params look at the point > they hit your controller ? And what''s in your model - it''s the one > thing you haven''t shown so far. > > FredAfter raising the parameters: ''tags: Defence'' is what''s returned. The model contains this line: ''acts_as_taggable_on :tags''. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pale Horse wrote:> Stephan Wehner wrote: >> Pale Horse wrote: > > Nothing short of what should be there, nothing more: > > def new > @article = Article.new > end > > def create > @article = Article.new(params[:article]) > if @article.save > flash[:notice] = "Successfully created article." > redirect_to admin_articles_path > else > render :action => ''new'' > end > end > > def edit > @article = Article.find(params[:id]) > end > > def update > @article = Article.find(params[:id]) > if @article.update_attributes(params[:article])I think you need to add something like, @article.tag_list << params[:tags] @article.save (Not the right way, but it should then save; sorry a bit late for me over here) Stephan> flash[:notice] = "Successfully updated article." > redirect_to admin_articles_path > else > render :action => ''edit'' > end > end-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Stephan Wehner wrote:> > Stephan Wehner wrote: > > I think you need to add something like, > > @article.tag_list << params[:tags] > @article.save > > (Not the right way, but it should then save; sorry a bit late for me > over here) > > Stephan >Apologies, using select_tag "article[tag_list]" sufficiently fixes this problem. Thank you for your input. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> Apologies, using select_tag "article[tag_list]" sufficiently fixes this > problem. > > Thank you for your input.Yes, that looks like the "right way". Except that the helper should be able to generate that ''select_tag'' with "f.select ''tag_list''" Are you not allowing several tags, as tags are normally used? Stephan -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Stephan Wehner wrote:> >> Apologies, using select_tag "article[tag_list]" sufficiently fixes this >> problem. >> >> Thank you for your input. > > Yes, that looks like the "right way". Except that the helper should be > able to generate that ''select_tag'' with "f.select ''tag_list''" > > Are you not allowing several tags, as tags are normally used? > > StephanCorrect. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.