1

I created an input page with a textbox in every field, and it's working.

I changed one field in the select box with the following code:

<div class="field">
    <%= f.label :position %><br />
    <%= select_tag "position", options_for_select(%w{ mainpost bannerpost2 minipost1 minipost2 minipost3 }) %> 
</div>

When I edit my new post, I change the select_tag value into bannerpost2, and then I update my post, but the field of position doesn't change into bannerpost2.


Also, when I edit my post, the f.select doesn't change automatically into it's value.

0

1 Answer 1

1
  • You need to use f.select instead of select_tag, because rails automatically append table name to each ids, f.select will be "post_position" if your table is "Posts", but select_tag will be just "position", so data won't get stored in db.

  • For previous value saved in db, should pass it as an arg to options_for_select

In case, if your table name is "Posts", pass @post.position

f.select :position, 
   options_for_select(%w{ mainpost bannerpost2 minipost1 minipost2 minipost3 },
   @post.position)
Sign up to request clarification or add additional context in comments.

2 Comments

is f.select syntax is the same as select_tag?
@mamatozay, yes, syntaxes are same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.