Render each model
fcontinitorres opened this issue · 6 comments
Hi nathanvda, I'm trying to show a modal all afternoon.
Not sure if I should ask this question here,
I would like to show an entire modal in my page
Using the example on the main page, I would like to do the following:
projects/_form
= semantic_form_for @project do |f|
= f.inputs do
= f.input :name
= f.input :description
%h3 Tasks
#tasks
= f.semantic_fields_for :tasks do |task|
= render 'task_fields', f: task
.links
= link_to_add_association 'add task', f, :tasks
= f.actions do
= f.action :submit
_task_fields
.nested-fields
That's what i want to do, task should show all attributes of model
= task
= f.inputs do
= f.input :description
= f.input :done, as: :boolean
= link_to_remove_association "remove task", f
Sorry for my bad english.
Hi, I edited your question a little to make the code a little more clear.
It is unclear to me 1) what is working, 2) what you are trying to achieve and 3) what is precisely going wrong?
Are you trying to show a modal
(pop-up window containing the form? I see no modal/js code?) or a model
?
Does it show the form for @project
but clicking the Add task
does not work?
Did you check out the demo project https://github.com/nathanvda/cocoon_simple_form_demo
Thanks for the edit.
My problem is that I don't know how to show a model/record (I don't know exactly how to call it) on the _task_fields page.
Imagine that I would use this page only in editing action, so their fields of model/record would already be defined.
I would like to show <% = task.description %> and below the edit input <% = f.input: description %>
.nested-fields
That's what i want to do, task should show all attributes of model
= task.description
= f.inputs do
= f.input :description
= f.input :done, as: :boolean
= link_to_remove_association "remove task", f
Thansk.
This looks fine. So to make it clear: you are editing an existing project, with existing tasks, and you do not see the tasks? Is that the case?
Instead of me editing the code: can you actually try and make sure the code in the question and following comments looks like the code in your editor? You can just edit your comments and mark the parts of text that are code as code (look at the icons at the top when editing) and make sure it looks correct.
Exactly, I'm editing an existing project, with existing tasks. I see the tasks in f.input, but would like to see them as = task, like:
= task.description
When i try to display = task.description I get the error:
undefined local variable or method `task' for #<#Class:0x00007feda16db0a0:0x00007feda48e5870>
Did you mean? task_url
Ah now I get it. Step by step, first you write:
= render 'task_fields', f: task
So in the partial _task_fields
the task
is known as f
(so the error is very right: task
is undefined at that stage), however ... this is a special object, created while iterating over the nested-items, so to actually reach the nested object itself, you have to write f.object
. In your case you would want to write:
= f.object.description
Thank you very much.
I realized that f was a simpleForm class, but couldn't find the .object
You are amazing.