Firstly it is better to try and use a subject line that indicates something about the problem.
2009/9/2 Nicholas Henry <[email protected]>: > > Hello Chris: > > I understand what you are attempting to do, but not sure the reasoning > behind it. In regards, to a new or edit forms, I would be incrementing > the account number when the form is posted. It might be worth looking > at the interface patterns developers use for ROR web applications > rather than thinking in terms of desktop Foxpro patterns. > > However having said that, to add additional methods, in a RESTFul > world I probably add it as another resource/controller. For example, > to increment an account number I would create a controller called > AccountNumbersController (i.e. for the resource account_number) with > an update method that does the increment. > > But without knowing your domain model this might be bad advice. > > As a last resort, you can always add it as another method in the > controller, but I like to keep the controllers to the REST methods, > and identify the resource I'm attempting to update and create a > controller for that. If you decide that a button to perform that action is what your UI requires then the button should submit a POST to an action of one of the controllers. It should be a POST as you are modifying the database and you do not want google accidentally GETing the URL that performs this action. You could have effectively an empty form with a submit button to so this, but I expect there is a way of doing it without a form, though I have never done this. Alternatively your main form can have multiple submit buttons so the action will go to the same action as your normal submit button but you can identify in the action which button has been pressed. The button id or name or something gets passed in the params. Look in the log at what happens when you press a button and you will see it. Since the action you describe does not seem to have anything to do with the main purpose of the form however this does not seem like the best approach. However you submit it, once the action is complete then display the original view again. Colin > > Cheers, > Nicholas > > On Sep 2, 1:57 pm, internetchris <[email protected]> > wrote: >> So this is a question that I keep trying to think through in my head >> and it's the first time I've had to implement it in an application. I >> come from a Visual Foxpro background and when I would want to add a >> button to a form I could simply place it on the form and then modify >> the clickevent with my custom code for that button. >> >> In rails if I'm working on the New or Edit form I want to add a >> button that finds the last record in the table, take the account >> number, and then increment it by one and then replace the contents of >> the account field on my form with that new number. Here's my >> question.... >> >> Do I add a separate method in my controller simply for this button (ie >> increment_account) or something like that? If I do this, how do I call >> that from my view? Do I always call it within a form by itself? This >> are fairly general questions, and probably ones I should know the >> answer to, but I'm finding that I'm not entirely sure how to implement >> little buttons that do special things within the "new" or "edit" >> views. If someone has the time to give me an example that would be >> awesome . I just want to know the proper way to implement something >> like this.. >> >> Thanks! >> >> Chris > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

