Reputation: 1047
I am trying to create many Lesson in one page using simple_form
The routes look like this
resources :schools do
resources :groups do
resources :lessons, only: [:new, :create, :destroy]
end
end
school_group_lessons POST /schools/:school_id/groups/:group_id/lessons(.:format) lessons#create
new_school_group_lesson GET /schools/:school_id/groups/:group_id/lessons/new(.:format) lessons#new
The form currently look like this(tried many variations but I always get an error)
= simple_form_for school_group_lesson_path [school_id: 1, group_id: 1, Lesson.new]. remote: true, method: :post do |f|
The error I get for this is
Can't assign to true 1, Lesson.new]. remote: true, method: :post do |f|; ^ /home/panda/workspace/Schooled/app/views/lessons/_form.html.slim:18: syntax error, unexpected keyword_end, expecting end-of-input _concat(("".freeze)); end; @output_buffer.safe_concat(( ^
which doesn't give me any clue on how to fix the problem... Could anyone tell me what am I doing wrong :? Thank you!
Upvotes: 0
Views: 220
Reputation: 196
You have a period instead of a comma on this line:
= simple_form_for school_group_lesson_path [school_id: 1, group_id: 1, Lesson.new]. remote: true, method: :post do |f|
try:
= simple_form_for school_group_lesson_path(school_id: 1, group_id: 1, Lesson.new), remote: true, method: :post do |f|
Note: the correct usage of simple_form_for is something like:
simple_form_for @lesson do |f|
f.input ....
end
Upvotes: 0
Reputation: 33542
There are a few mistakes I can point out for you
You have a dot(.) after [school_id: 1, group_id: 1, Lesson.new]
which should be a comma(,)
This is wrong [school_id: 1, group_id: 1, Lesson.new]
. You should give the instances of school
and group
as arguments along with Lesson.new
The form path is messed up. It should be either
= simple_form_for school_group_lessons_path(@school_instance,@group_instance,Lesson.new), remote: true, method: :post do |f|
OR
= simple_form_for [@school_instance,@group_instance,Lesson.new], remote: true, method: :post do |f|
Also notice that school_group_lesson_path
should be school_group_lessons_path
Finally make sure you define the required school
and group
instances in the controller#action
Upvotes: 3