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

<%= f.label "Tags" %>
<%= select_tag "tags", "Value 1Value 2Value 3Value 4Value 5Value 6" %>

<%= f.submit "Submit" %>

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

On Jul 29, 3:53 pm, Pale H. [email protected] 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?

Fred

Frederick C. wrote:

On Jul 29, 3:53�pm, Pale H. [email protected] wrote:

� � <%= select_tag “tags”, "Value 1Value

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

I’ve already checked, there are none.

Stephan W. 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 H. wrote:

Stephan W. 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

Could it be that your template should say

<%= f.select “tags”, … %>

and not

<%= select_tag “tags”, … %>

Stephan

On Jul 30, 9:15 am, Pale H. [email protected] wrote:

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

Stephan W. wrote:

Pale H. wrote:

Stephan W. 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

Frederick C. wrote:

On Jul 30, 9:15�am, Pale H. [email protected] 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 H. wrote:

Stephan W. wrote:

Pale H. 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

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 W. wrote:

Stephan W. 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.

Stephan W. 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.