-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use form_for with ViewModel #260
Comments
You have to include We can think about a cells helper module that provides that out-of-the-box but on the other hand I want to increase the pain so that users like you report to Rails core and probably push them to remove those dependencies from core. 😬 |
It still looks the same. I've added this two methods (delegate to def dom_class(record, prefix = nil)
ActionView::RecordIdentifier.dom_class(record, prefix)
end
def dom_id(record, prefix = nil)
ActionView::RecordIdentifier.dom_id(record, prefix)
end Both returns in my case 'new_article' (so I think value is ok), but form still doesn't render correctly: <input type="text" name="article[title]" id="article_title" />
<form class="new_article" id="new_article" ...></form> I've also checked how it works in cells 4.0. So I included
Do you have any idea what I am doing wrong? |
@st0mir can you try with my fork + addition of cells-haml ? |
It works but not without problems. I've got exception:
so, I've changed There was also problem with two missing methods on String:
so I had to include to String this modules:
|
Can you send a PR ? |
I am also trying to use form_for in a cell but I have a problem that is not mentioned here.
I use rails 4.2, cells master and cells-haml form_tag_with_body branch from st0mir I checked the form_tag_with_body method in lib/cell/haml.rb (cells-haml) and the content parameter is nil. If I force the content to be an empty string it does not crash. I would be glad to tell you more details if needed. |
You should use either my fork or cell-4 branch. Master is too hacky. |
Same error with the cells-4 branch. But if I change the form_tag_with_body method like this def form_tag_with_body(html_options, content)
content ||= ""
"#{form_tag_html(html_options)}" << content << "</form>"
end my problem is solved. (no idea of other consequences 😓) |
I'm going to fix it |
This is just wrong per design - why is a view component library supposed to fix these kind of template engine details. I really hope we can set a usable standard with I merged seuros cleanup, cells/cells-4 is now the authorative source for our future work. Thanks to @seuros for his work on extracting template engine specific logic to gems! ❤️ 🍻 ah no wait, he doesn't drink alcohol.... 🍵 |
🍸 |
I need the gem |
cells-haml is for cells 4.x only. |
I guess I will just hack it myself Q_Q |
Why do you need that for cells 3 anyway, @PikachuEXE? |
cells 3 also got |
But... I don't understand... how is the |
In one of my concept cell I need to use # Required by simple form for `form_for` I guess
include ActionView::RecordIdentifier
include ActionView::Helpers::FormHelper
include SimpleForm::ActionViewExtensions::FormHelper Then it will out put escaped HTML |
Would using cells 4.0 be a choice for you? |
For now I would be using my hacks. |
Ok, if your hacks work, then I'm happy. Sorry for the inconvenience - everything will be better in Cells 4. |
Just wanted to point out that this still doesn't work in Cells 4 (I'm not sure if it should; I'd like it to, but that's not my decision). Thankfully, @PikachuEXE descended like an angel, and sprinkled magical dust upon my code, allowing it to just work. I'm using this concern to get it working with Formtastic: module FormsForCells
extend ActiveSupport::Concern
included do
include ActionView::RecordIdentifier
include ActionView::Helpers::FormHelper
include ActionView::Helpers::TextHelper
include ActionView::Context
include Formtastic::Helpers::FormHelper
include Cell::Haml
end
end |
You have to tell the formtastic guys to fix that in their code. They are not including necessary helpers in their modules and assume that everything is automatically/magically there, which is the case in Rails but not in Cells or in other Ruby environments. Do me a favour and open a ticket there, telling them to include the necessary modules in |
Don't put and "workaround" (not fix) in this gem, no. |
Thanks for the idea, @shkm. Using Cells 4 (and cells-rails and cells-haml and simple_form). I had to make a concern / module to include in my cells as the list of includes was as long as yours. It would be nice if cells-rails or cells-haml would do some of this themselves, but I guess there's both pros and cons to having stuff automagically included into Cell::Concept |
How to use form_for helper in Cell::ViewModel?
Without including this helper I get error 'method undefined'. So I've tried to include it:
include ActionView::RecordIdentifier # this I need for method dom_class that is used by form_tag include ActionView::Helpers::FormHelper
but now input tags are not nested in form tag. It looks like this:
``<input ... />
<input ... />
Am I doing something wrong?
My rails version is 4.2.0
The text was updated successfully, but these errors were encountered: