Tags not being saved into the database

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.

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

Frederick Cheung wrote:

Could it be that your template should say

<%= f.select "tags", ... %>

and not

<%= select_tag "tags", ... %>

Stephan

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.

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

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?

Stephan

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])       flash[:notice] = "Successfully updated article."       redirect_to admin_articles_path     else       render :action => 'edit'     end   end

> <%= 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

Frederick Cheung 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.

Fred

After raising the parameters: 'tags: Defence' is what's returned. The model contains this line: 'acts_as_taggable_on :tags'.

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

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.

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

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?

Stephan

Correct.