4 ms·
General advice first :) If you can't get stuff working with the rails helpers you can always hand write the html yourself. I need to do this once in awhile. I
by epochwolf 16y ago
General advice first :)
If you can't get stuff working with the rails helpers you can always hand write the html yourself. I need to do this once in awhile. I prefer using formtastic for my current project and I've had to hand write some html to add custom logic to a formtastic form. (I prefer not to abstract one off hacks until I need to do it twice)
Rails does a lot of stuff but it doesn't do everything. If the built in tools don't do it, build your own.
> 1. I'd like several submit buttons on a form that do different things.
The only way to target these is javascript hackery, use the text on the submit button or find an alternative method that doesn't rely on multiple forms.
> 2. If you have two forms on a page, can you set it up so changes on both forms are saved when any submit button is clicked?
Without javascript, not happening. For a rails solution to combine two forms, look at fields_for.
All that said,
Without specific details (screenshots, etc.) I can't really figure out what you are trying to do. I assume you have a valid reason for asking the question. Sorry if I wasn't able to help.
- Robin_Message 16y agoThanks, this was helpful, especially fields_for. On the point of building my own, that's what I've done, but these felt like an obvious things to want (I implemented them both in my own PHP framework.) Thinking about it, the standard Rails CRUD index provides delete links instead of buttons; IMHO that is totally wrong, but when all you have is a hammer... Also, button_to is not good enough as it makes its own form, which breaks any solution to question 2. On question 1, what I want is to generate submit buttons like <input type=submit name=some_non_clashing_string_that_identifies_this_button value=ButtonText> and then have this routed to a function nicely. I've not found a standard way of doing that; maybe I should write one? Could you see it being useful?
- epochwolf 16y agoIt definitely sounds like you are doing something wrong. Rails really wants you to do things it's way. You don't have to, rails, especially version 3, is only generated html and routes to functions. It just generates a lot of stuff for you. If you want to work outside of the provided functionality it's just going to be harder. In fact the application I'm using at work right now uses ExtJS for views and half of the data is retrieved through manual queries. Rails is not designed to do this but it can work, if you are willing to put in the effort to work around missing functionality. I do not recommend using rails as a hammer, it's a very bad hammer. It's a chainsaw with diamond teeth and a 50 hp gas-powered engine. If you have a lot of wood to chop through, it's amazing. If you need to pound in a few nails, it's a little awkward. :)
- xentronium 16y agoYep, for something simple just use Sinatra / other microframeworks.