I.B
I.B

Reputation: 2923

Use update_attributes with value entered by user

What I'm trying to do is update only one value of my object. I was able to do this part when I put the value myself but I am trying to have the user enter the value he wants and then using that value update my attribute.

<td><%= text_field(:referent, :titre, size: 20) %>
<%= link_to(referent.titre,  referent_path(referent, "referent[titre]" => "Changed"), :method => :put) %></td>

Right now I just have the value "Changed" in it and that works it changes the value of my attribute titre but I can't figure out how to take the value from the text_field and put it at the place of "Changed"

This is my update method

def update
  @referents = Referent.find(params[:id])
    if @referents.update_attributes(referent_params)
  end
end

Upvotes: 1

Views: 61

Answers (1)

toastytheog
toastytheog

Reputation: 48

It doesn't look like you are submitting the form results, but instead linking to another page and setting the param for titre in the url. Try this:

<%=form_for @referents do |f| %>
<%=f.label :titre%>
<%=f.text_field :titre, size: 20%>
<%=f.submit%>

Upvotes: 2

Related Questions