F
F
FanKiLL2014-08-08 01:15:40
MySQL
FanKiLL, 2014-08-08 01:15:40

How is it implemented on toster.ru in the profile adding links to social networks, jabber, etc.?

Is it really many to one

class User < ActiveRecord::Base
  has_many :links, dependent: :destroy
end

class Link < ActiveRecord::Base
  belongs_to :user
end

It is the view part that is of interest, how to put it all into the form, and how to recognize new links on the server and which old ones need to be updated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krokodily, 2015-07-27
@krokodily

I did so

<%= form_for @festival do |festival_form| %>
    <div id="social_networks_fields">
      <%= festival_form.fields_for :social_networks do |social_network_fields| %>
        <%= render 'social_network_fields', f: social_network_fields %>
      <% end %>
    </div>
<% end %>

<!--_social_network_fields.html.erb-->
<%= f.select :network, SocialNetwork.networks.keys %>
<%= f.text_field :link %>

The SocialNetwork model must have a network field as an enum.
class SocialNetwork < ActiveRecord::Base
  belongs_to :festivals
  enum network: [:facebook, :vkontakte, :twitter, :linkedin, :vimeo, :flickr,
                 :google, :youtube]
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question