How to render different forms on show page












0















I have Event model with a kind column. The Event can be either a training camp, conference, etc.

Right now on every event page I display a form for a Customer so that a client can register for this particular Event. Customer belongs_to Event.



Now, I would like to have a new kind of Event and for this specific event I need to display additional fields in the form for the customer. Customer table does not have these columns. The fields should be like location, training date, parent name, parent phone, etc.



Of course, the new fields should be validated upon input. I know how to render different forms conditionally on the event show page but I am not quite sure where to add the new columns and how to handle it in the controller. I wouldn't like to add these columns to Customer table because I think they do not really belong there.

Besides, I need to validate the new fields as well so there will be a situation where I render different forms and I can't validate all the fields if just one specific form is rendered.



Do you have any ideas how I could go about this?










share|improve this question





























    0















    I have Event model with a kind column. The Event can be either a training camp, conference, etc.

    Right now on every event page I display a form for a Customer so that a client can register for this particular Event. Customer belongs_to Event.



    Now, I would like to have a new kind of Event and for this specific event I need to display additional fields in the form for the customer. Customer table does not have these columns. The fields should be like location, training date, parent name, parent phone, etc.



    Of course, the new fields should be validated upon input. I know how to render different forms conditionally on the event show page but I am not quite sure where to add the new columns and how to handle it in the controller. I wouldn't like to add these columns to Customer table because I think they do not really belong there.

    Besides, I need to validate the new fields as well so there will be a situation where I render different forms and I can't validate all the fields if just one specific form is rendered.



    Do you have any ideas how I could go about this?










    share|improve this question



























      0












      0








      0








      I have Event model with a kind column. The Event can be either a training camp, conference, etc.

      Right now on every event page I display a form for a Customer so that a client can register for this particular Event. Customer belongs_to Event.



      Now, I would like to have a new kind of Event and for this specific event I need to display additional fields in the form for the customer. Customer table does not have these columns. The fields should be like location, training date, parent name, parent phone, etc.



      Of course, the new fields should be validated upon input. I know how to render different forms conditionally on the event show page but I am not quite sure where to add the new columns and how to handle it in the controller. I wouldn't like to add these columns to Customer table because I think they do not really belong there.

      Besides, I need to validate the new fields as well so there will be a situation where I render different forms and I can't validate all the fields if just one specific form is rendered.



      Do you have any ideas how I could go about this?










      share|improve this question
















      I have Event model with a kind column. The Event can be either a training camp, conference, etc.

      Right now on every event page I display a form for a Customer so that a client can register for this particular Event. Customer belongs_to Event.



      Now, I would like to have a new kind of Event and for this specific event I need to display additional fields in the form for the customer. Customer table does not have these columns. The fields should be like location, training date, parent name, parent phone, etc.



      Of course, the new fields should be validated upon input. I know how to render different forms conditionally on the event show page but I am not quite sure where to add the new columns and how to handle it in the controller. I wouldn't like to add these columns to Customer table because I think they do not really belong there.

      Besides, I need to validate the new fields as well so there will be a situation where I render different forms and I can't validate all the fields if just one specific form is rendered.



      Do you have any ideas how I could go about this?







      ruby-on-rails






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 12:15







      jedi

















      asked Nov 22 '18 at 9:10









      jedijedi

      567417




      567417
























          1 Answer
          1






          active

          oldest

          votes


















          1














          User attr_accessor in customer model for mass assigning the new fields



          attr_accessor: :location,:training_date etc


          Now you pass those values from form with model object . And you can right condition in "Pratial or View"



          If you want store those values in DB table then you have to create columns in Customer Model. Or if you don't want to create fields in customer table then you can use "Redis" for storage the values.






          share|improve this answer
























          • If I add the new columns to Customer, how would I go about validating them conditionally in each specific scenario? For example, if the event is a training, do not validate those extra fields, if it is a conference validate different fields.

            – jedi
            Nov 22 '18 at 12:14











          • once you have added attr_accessor then you can write validation for those fields in model . like using "validates ", other wise you can use custom validations . Or else you can use JavaScript if it is applicable to you .

            – user3678149
            Nov 22 '18 at 13:12











          • surely you can use custom validations. Like below code. validate :customer_event def customer_event -- here you can write your condition -- if self.event == "training" --- do ---- end end

            – user3678149
            Nov 22 '18 at 13:13













          • If you have any doubt on custom validations then lemme know I will update the answer . Thank you

            – user3678149
            Nov 22 '18 at 13:15











          • if self.event == "training" does not work - undefined variable or method 'self' I tried also if event == training but got undefined variable or method 'event'. Could you help me?

            – jedi
            Nov 22 '18 at 16:38













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427337%2fhow-to-render-different-forms-on-show-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          User attr_accessor in customer model for mass assigning the new fields



          attr_accessor: :location,:training_date etc


          Now you pass those values from form with model object . And you can right condition in "Pratial or View"



          If you want store those values in DB table then you have to create columns in Customer Model. Or if you don't want to create fields in customer table then you can use "Redis" for storage the values.






          share|improve this answer
























          • If I add the new columns to Customer, how would I go about validating them conditionally in each specific scenario? For example, if the event is a training, do not validate those extra fields, if it is a conference validate different fields.

            – jedi
            Nov 22 '18 at 12:14











          • once you have added attr_accessor then you can write validation for those fields in model . like using "validates ", other wise you can use custom validations . Or else you can use JavaScript if it is applicable to you .

            – user3678149
            Nov 22 '18 at 13:12











          • surely you can use custom validations. Like below code. validate :customer_event def customer_event -- here you can write your condition -- if self.event == "training" --- do ---- end end

            – user3678149
            Nov 22 '18 at 13:13













          • If you have any doubt on custom validations then lemme know I will update the answer . Thank you

            – user3678149
            Nov 22 '18 at 13:15











          • if self.event == "training" does not work - undefined variable or method 'self' I tried also if event == training but got undefined variable or method 'event'. Could you help me?

            – jedi
            Nov 22 '18 at 16:38


















          1














          User attr_accessor in customer model for mass assigning the new fields



          attr_accessor: :location,:training_date etc


          Now you pass those values from form with model object . And you can right condition in "Pratial or View"



          If you want store those values in DB table then you have to create columns in Customer Model. Or if you don't want to create fields in customer table then you can use "Redis" for storage the values.






          share|improve this answer
























          • If I add the new columns to Customer, how would I go about validating them conditionally in each specific scenario? For example, if the event is a training, do not validate those extra fields, if it is a conference validate different fields.

            – jedi
            Nov 22 '18 at 12:14











          • once you have added attr_accessor then you can write validation for those fields in model . like using "validates ", other wise you can use custom validations . Or else you can use JavaScript if it is applicable to you .

            – user3678149
            Nov 22 '18 at 13:12











          • surely you can use custom validations. Like below code. validate :customer_event def customer_event -- here you can write your condition -- if self.event == "training" --- do ---- end end

            – user3678149
            Nov 22 '18 at 13:13













          • If you have any doubt on custom validations then lemme know I will update the answer . Thank you

            – user3678149
            Nov 22 '18 at 13:15











          • if self.event == "training" does not work - undefined variable or method 'self' I tried also if event == training but got undefined variable or method 'event'. Could you help me?

            – jedi
            Nov 22 '18 at 16:38
















          1












          1








          1







          User attr_accessor in customer model for mass assigning the new fields



          attr_accessor: :location,:training_date etc


          Now you pass those values from form with model object . And you can right condition in "Pratial or View"



          If you want store those values in DB table then you have to create columns in Customer Model. Or if you don't want to create fields in customer table then you can use "Redis" for storage the values.






          share|improve this answer













          User attr_accessor in customer model for mass assigning the new fields



          attr_accessor: :location,:training_date etc


          Now you pass those values from form with model object . And you can right condition in "Pratial or View"



          If you want store those values in DB table then you have to create columns in Customer Model. Or if you don't want to create fields in customer table then you can use "Redis" for storage the values.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 9:33









          user3678149user3678149

          1776




          1776













          • If I add the new columns to Customer, how would I go about validating them conditionally in each specific scenario? For example, if the event is a training, do not validate those extra fields, if it is a conference validate different fields.

            – jedi
            Nov 22 '18 at 12:14











          • once you have added attr_accessor then you can write validation for those fields in model . like using "validates ", other wise you can use custom validations . Or else you can use JavaScript if it is applicable to you .

            – user3678149
            Nov 22 '18 at 13:12











          • surely you can use custom validations. Like below code. validate :customer_event def customer_event -- here you can write your condition -- if self.event == "training" --- do ---- end end

            – user3678149
            Nov 22 '18 at 13:13













          • If you have any doubt on custom validations then lemme know I will update the answer . Thank you

            – user3678149
            Nov 22 '18 at 13:15











          • if self.event == "training" does not work - undefined variable or method 'self' I tried also if event == training but got undefined variable or method 'event'. Could you help me?

            – jedi
            Nov 22 '18 at 16:38





















          • If I add the new columns to Customer, how would I go about validating them conditionally in each specific scenario? For example, if the event is a training, do not validate those extra fields, if it is a conference validate different fields.

            – jedi
            Nov 22 '18 at 12:14











          • once you have added attr_accessor then you can write validation for those fields in model . like using "validates ", other wise you can use custom validations . Or else you can use JavaScript if it is applicable to you .

            – user3678149
            Nov 22 '18 at 13:12











          • surely you can use custom validations. Like below code. validate :customer_event def customer_event -- here you can write your condition -- if self.event == "training" --- do ---- end end

            – user3678149
            Nov 22 '18 at 13:13













          • If you have any doubt on custom validations then lemme know I will update the answer . Thank you

            – user3678149
            Nov 22 '18 at 13:15











          • if self.event == "training" does not work - undefined variable or method 'self' I tried also if event == training but got undefined variable or method 'event'. Could you help me?

            – jedi
            Nov 22 '18 at 16:38



















          If I add the new columns to Customer, how would I go about validating them conditionally in each specific scenario? For example, if the event is a training, do not validate those extra fields, if it is a conference validate different fields.

          – jedi
          Nov 22 '18 at 12:14





          If I add the new columns to Customer, how would I go about validating them conditionally in each specific scenario? For example, if the event is a training, do not validate those extra fields, if it is a conference validate different fields.

          – jedi
          Nov 22 '18 at 12:14













          once you have added attr_accessor then you can write validation for those fields in model . like using "validates ", other wise you can use custom validations . Or else you can use JavaScript if it is applicable to you .

          – user3678149
          Nov 22 '18 at 13:12





          once you have added attr_accessor then you can write validation for those fields in model . like using "validates ", other wise you can use custom validations . Or else you can use JavaScript if it is applicable to you .

          – user3678149
          Nov 22 '18 at 13:12













          surely you can use custom validations. Like below code. validate :customer_event def customer_event -- here you can write your condition -- if self.event == "training" --- do ---- end end

          – user3678149
          Nov 22 '18 at 13:13







          surely you can use custom validations. Like below code. validate :customer_event def customer_event -- here you can write your condition -- if self.event == "training" --- do ---- end end

          – user3678149
          Nov 22 '18 at 13:13















          If you have any doubt on custom validations then lemme know I will update the answer . Thank you

          – user3678149
          Nov 22 '18 at 13:15





          If you have any doubt on custom validations then lemme know I will update the answer . Thank you

          – user3678149
          Nov 22 '18 at 13:15













          if self.event == "training" does not work - undefined variable or method 'self' I tried also if event == training but got undefined variable or method 'event'. Could you help me?

          – jedi
          Nov 22 '18 at 16:38







          if self.event == "training" does not work - undefined variable or method 'self' I tried also if event == training but got undefined variable or method 'event'. Could you help me?

          – jedi
          Nov 22 '18 at 16:38






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427337%2fhow-to-render-different-forms-on-show-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]