How to have a field that has a different params value to the displayed name











up vote
0
down vote

favorite












I have a form that collects an email address.



  <%= form_tag accounts_path, :method => :post do %>
<div class="field">
<%= label_tag :email %><br />
<%= text_field_tag :homeEmail %>
</div>
<div class="Section-button">
<div class="actions">
<%= submit_tag "Update", class: 'btn btn-primary' %>
</div>
</div>
<% end %>


I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].



I want to use a capybara feature spec test such as



  fill_in 'Email', with: user.email, match: :first
click_button Update


but I receive the error:



Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element


The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to



<%= text_field_tag :email %>


but this does not work in the controller because the params is params[:email] not params[:homeEmail].



How do I get this test working?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a form that collects an email address.



      <%= form_tag accounts_path, :method => :post do %>
    <div class="field">
    <%= label_tag :email %><br />
    <%= text_field_tag :homeEmail %>
    </div>
    <div class="Section-button">
    <div class="actions">
    <%= submit_tag "Update", class: 'btn btn-primary' %>
    </div>
    </div>
    <% end %>


    I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].



    I want to use a capybara feature spec test such as



      fill_in 'Email', with: user.email, match: :first
    click_button Update


    but I receive the error:



    Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element


    The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to



    <%= text_field_tag :email %>


    but this does not work in the controller because the params is params[:email] not params[:homeEmail].



    How do I get this test working?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a form that collects an email address.



        <%= form_tag accounts_path, :method => :post do %>
      <div class="field">
      <%= label_tag :email %><br />
      <%= text_field_tag :homeEmail %>
      </div>
      <div class="Section-button">
      <div class="actions">
      <%= submit_tag "Update", class: 'btn btn-primary' %>
      </div>
      </div>
      <% end %>


      I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].



      I want to use a capybara feature spec test such as



        fill_in 'Email', with: user.email, match: :first
      click_button Update


      but I receive the error:



      Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element


      The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to



      <%= text_field_tag :email %>


      but this does not work in the controller because the params is params[:email] not params[:homeEmail].



      How do I get this test working?










      share|improve this question













      I have a form that collects an email address.



        <%= form_tag accounts_path, :method => :post do %>
      <div class="field">
      <%= label_tag :email %><br />
      <%= text_field_tag :homeEmail %>
      </div>
      <div class="Section-button">
      <div class="actions">
      <%= submit_tag "Update", class: 'btn btn-primary' %>
      </div>
      </div>
      <% end %>


      I have the field tag for the email being :homeEmail because I want to recover it in the controller using params[:homeEmail].



      I want to use a capybara feature spec test such as



        fill_in 'Email', with: user.email, match: :first
      click_button Update


      but I receive the error:



      Unable to find visible field "Email" that is not disabled within #<Capybara::Node::Element


      The element is not disabled, and when I try the page in development mode it works. The test fills in the field if I just change the text_field_tag to



      <%= text_field_tag :email %>


      but this does not work in the controller because the params is params[:email] not params[:homeEmail].



      How do I get this test working?







      ruby-on-rails rspec capybara






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 8:18









      Obromios

      4,01322764




      4,01322764
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          fill_in finds the element to fill by name, id, or associated label text. When you're doing fill_in 'Email', ... I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for attribute doesn't match the inputs id attribute). The fix is to change your view to correctly associate the label with the field



          <%= form_tag accounts_path, :method => :post do %>
          <div class="field">
          <%= label_tag :homeEmail, 'Email' %><br />
          <%= text_field_tag :homeEmail %>
          </div>
          ...


          Then your fill_in 'Email', with: user.email should work correctly






          share|improve this answer




























            up vote
            1
            down vote













            Instead of doing:



              fill_in 'Email', with: user.email, match: :first


            You should do:



              fill_in 'homeEmail', with: user.email, match: :first


            Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %> it will generate <input type="text" name="homeEmail" id="homeEmail"> but while filling it you're using Email as a selector for which capybara is not able to find any element.



            Let me know if it helps!






            share|improve this answer





















            • I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
              – Obromios
              Nov 21 at 3:21











            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',
            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%2f53370692%2fhow-to-have-a-field-that-has-a-different-params-value-to-the-displayed-name%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            fill_in finds the element to fill by name, id, or associated label text. When you're doing fill_in 'Email', ... I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for attribute doesn't match the inputs id attribute). The fix is to change your view to correctly associate the label with the field



            <%= form_tag accounts_path, :method => :post do %>
            <div class="field">
            <%= label_tag :homeEmail, 'Email' %><br />
            <%= text_field_tag :homeEmail %>
            </div>
            ...


            Then your fill_in 'Email', with: user.email should work correctly






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              fill_in finds the element to fill by name, id, or associated label text. When you're doing fill_in 'Email', ... I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for attribute doesn't match the inputs id attribute). The fix is to change your view to correctly associate the label with the field



              <%= form_tag accounts_path, :method => :post do %>
              <div class="field">
              <%= label_tag :homeEmail, 'Email' %><br />
              <%= text_field_tag :homeEmail %>
              </div>
              ...


              Then your fill_in 'Email', with: user.email should work correctly






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                fill_in finds the element to fill by name, id, or associated label text. When you're doing fill_in 'Email', ... I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for attribute doesn't match the inputs id attribute). The fix is to change your view to correctly associate the label with the field



                <%= form_tag accounts_path, :method => :post do %>
                <div class="field">
                <%= label_tag :homeEmail, 'Email' %><br />
                <%= text_field_tag :homeEmail %>
                </div>
                ...


                Then your fill_in 'Email', with: user.email should work correctly






                share|improve this answer












                fill_in finds the element to fill by name, id, or associated label text. When you're doing fill_in 'Email', ... I assume you're intending it to use the associated label text option. The issue you're having is that the label isn't actually associated with the field (if you look at the HTML source you'll see the labels for attribute doesn't match the inputs id attribute). The fix is to change your view to correctly associate the label with the field



                <%= form_tag accounts_path, :method => :post do %>
                <div class="field">
                <%= label_tag :homeEmail, 'Email' %><br />
                <%= text_field_tag :homeEmail %>
                </div>
                ...


                Then your fill_in 'Email', with: user.email should work correctly







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 19 at 11:15









                Thomas Walpole

                29.3k32546




                29.3k32546
























                    up vote
                    1
                    down vote













                    Instead of doing:



                      fill_in 'Email', with: user.email, match: :first


                    You should do:



                      fill_in 'homeEmail', with: user.email, match: :first


                    Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %> it will generate <input type="text" name="homeEmail" id="homeEmail"> but while filling it you're using Email as a selector for which capybara is not able to find any element.



                    Let me know if it helps!






                    share|improve this answer





















                    • I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
                      – Obromios
                      Nov 21 at 3:21















                    up vote
                    1
                    down vote













                    Instead of doing:



                      fill_in 'Email', with: user.email, match: :first


                    You should do:



                      fill_in 'homeEmail', with: user.email, match: :first


                    Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %> it will generate <input type="text" name="homeEmail" id="homeEmail"> but while filling it you're using Email as a selector for which capybara is not able to find any element.



                    Let me know if it helps!






                    share|improve this answer





















                    • I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
                      – Obromios
                      Nov 21 at 3:21













                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Instead of doing:



                      fill_in 'Email', with: user.email, match: :first


                    You should do:



                      fill_in 'homeEmail', with: user.email, match: :first


                    Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %> it will generate <input type="text" name="homeEmail" id="homeEmail"> but while filling it you're using Email as a selector for which capybara is not able to find any element.



                    Let me know if it helps!






                    share|improve this answer












                    Instead of doing:



                      fill_in 'Email', with: user.email, match: :first


                    You should do:



                      fill_in 'homeEmail', with: user.email, match: :first


                    Since capybara tries to find an element with id or name attributes if you're doing <%= text_field_tag :homeEmail %> it will generate <input type="text" name="homeEmail" id="homeEmail"> but while filling it you're using Email as a selector for which capybara is not able to find any element.



                    Let me know if it helps!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 19 at 9:43









                    eurodo061

                    364




                    364












                    • I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
                      – Obromios
                      Nov 21 at 3:21


















                    • I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
                      – Obromios
                      Nov 21 at 3:21
















                    I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
                    – Obromios
                    Nov 21 at 3:21




                    I have upvoted this because it works and is potentially useful in other cases, but I have accepted Walpole's answer because it allows me to use the test without modification.
                    – Obromios
                    Nov 21 at 3:21


















                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53370692%2fhow-to-have-a-field-that-has-a-different-params-value-to-the-displayed-name%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

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin