У меня есть этот код рубина для переключателей в моей пользовательской форме new
:
<%= f.fields_for :profile, Profile.new do |t| %>
<div class ="field">
<%= t.label :type, "Are you an artist or listener?" %><br />
<p> Artist: <%= t.radio_button :type, "artist" %></p>
<p> Listener: <%= t.radio_button :type, "listener" %></p>
</div>
<% end %>
Я хочу установить атрибут type
моей модели профиля.Однако тип не задан и по умолчанию равен nil
.Я попытался создать этот метод create
в контроллере своего профиля, но он не сработал:
def create
@profile = Profile.find(params[:id])
if params[:profile_attributes][:type] == "artist"
@profile.type = "artist"
elsif params[:profile_attributes][:type] == "listener"
@profile.type = "listener"
end
end
Как мне правильно установить type
для "Artist" или "Listener"?
ОБНОВЛЕНИЕ:
Я получаю эту ошибку: WARNING: Can't mass-assign protected attributes: type