ruby - Rails getter and setter functions not working with form -



ruby - Rails getter and setter functions not working with form -

my form looks such on profile model:

<%= form_for @profile |f| %> <div class="form-group"> <%= f.label :email, "email" %> <%= f.text_field :email, class: "form-control" %> <%= f.label :tag_list, "hello!" %> <%= f.text_field :tag_list %> </div> <%= f.submit "submit", class: "btn btn-success" %> <%end%>

and have tag model want apply tags to.

my getter/setter functions:

def tag_list rails.logger.error "names" tags.map(&:tag_name).join(", ") end def tag_list=(names) self.tags = names.split(",").map |n| rails.logger.error "names" self.tags.where(tag_name: n.strip).first_or_create! end end

and controller:

def update redirect_to profile_path(params[:id]) end def edit end

it doesn't save tags profile nor see logs in log file.

the update action nil redirect, @profile unchanged. setter methods not run until phone call @profile.update_attributes(params[:profile]) or similar method.

ruby-on-rails ruby

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -