После того, как пользователь отправил challenge.name
, как направить его в форму, где он может закончить ввод атрибутов объекта?new_path после ввода признака атрибута?
challenges_controller
#user chooses featured challenge.name or creates custom challenge.name
def featured
@challenge = Challenge.new
end
#If user created a custom challenge.name how to redirect him to "def new" to fill out the rest of the challenge's attributes
def new
@challenge = Challenge.new
@challenge.name = challenge_params[:name]
if @challenge.name == 'Journal'
@challenge.category = 'habit'
elsif @challenge.name == 'Meditate'
@challenge.category = 'habit'
elsif @challenge.name == 'Run a Mile'
@challenge.category = 'habit'
else
@challenge.category = 'goal'
end
end
def create
@challenge = Challenge.new(challenge_params)
@challenge.save
redirect_to @challenge
end
проблемы/featured.html.erb
<%= simple_form_for(@challenge) do |f| %>
<%= f.text_field :name,'Enter Custom Challenge' %>
Or choose a featured challenge:
<%= link_to 'New Challenge', new_challenge_path(name: 'Journal') %>
<%= link_to 'New Challenge', new_challenge_path(name: 'Meditate') %>
<%= link_to 'New Challenge', new_challenge_path(name: 'Run a Mile') %>
<%= f.submit %>
<% end %>
вызовы/новые
<%= simple_form_for(@challenge) do |f| %>
<%= f.text_field :name %>
<%= f.radio_button :category, 'goal', class: 'date-format-switcher' %>
<label for="challenge_category_goal">Goal</label>
<%= f.radio_button :category, 'habit', class: 'date-format-switcher' %>
<label for="challenge_category_habit">Habit</label>
etc....
Что вы подразумеваете под вызовом.name? – coderVishal
также расскажите, как работает путь создания – coderVishal
'.name' является атрибутом для вызова @coderVishal. Пользователь может писать в пользовательском '.name' для своей задачи в' text_field'. Я хочу, чтобы это перейти от признанной формы к новой. Я обновил вопрос с созданием действия:] –