Skip to content
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

Refactor error message in _edit_form.html.erb, partial fix for #8545 #8553

Merged
merged 2 commits into from
Oct 13, 2020

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Oct 12, 2020

Partially fixes #8545 in one location: plots2/app/views/users/_edit_form.html.erb

@noi5e noi5e requested a review from a team as a code owner October 12, 2020 22:22
@gitpod-io
Copy link

gitpod-io bot commented Oct 12, 2020

@noi5e noi5e changed the title Refactor error message in _edit_form.html.erb Refactor error message in _edit_form.html.erb, partial fix for #8545 Oct 12, 2020
@codecov
Copy link

codecov bot commented Oct 12, 2020

Codecov Report

Merging #8553 into main will decrease coverage by 0.03%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8553      +/-   ##
==========================================
- Coverage   81.91%   81.88%   -0.04%     
==========================================
  Files         101      101              
  Lines        5896     5901       +5     
==========================================
+ Hits         4830     4832       +2     
- Misses       1066     1069       +3     
Impacted Files Coverage Δ
app/controllers/stats_controller.rb 71.87% <50.00%> (-1.76%) ⬇️

@noi5e
Copy link
Contributor Author

noi5e commented Oct 13, 2020

@jywarren I'm guessing I should be concered about Travis CI not passing, any tips?

I have to admit, I have some familiarity with Ruby, but more with JS. I wonder if there's something wrong with my syntax that's causing any errors?

Also, maybe I should actually test this out locally. 🤦‍♂️ I'm still getting used to the codebase-- do you know where exactly this code is used, and how to see it in action? I'm guessing this is for something like updating userinfo in the profile page. Thanks for the help

@jywarren
Copy link
Member

Hi, no problem! The test logs should show us what went wrong. Indeed, this should be when editing your profile, at /profile

Let's see --

image

We could try these out by opening the code in GitPod using the button above. But, let's see if the errors are readable.

An integration test failed:


ERROR["test_should_choose_i18n_for_user/_photo_+_user/edit", #<Minitest::Reporters::Suite:0x000000000b29edd8 @name="I18nTest">, 110.85859752900004]
 test_should_choose_i18n_for_user/_photo_+_user/edit#I18nTest (110.86s)
Minitest::UnexpectedError:         ActionView::Template::Error: undefined method `errors' for nil:NilClass
            app/views/users/_edit_form.html.erb:5:in `block in _app_views_users__edit_form_html_erb___2356090617493035158_99485120'
            app/views/users/_edit_form.html.erb:2:in `_app_views_users__edit_form_html_erb___2356090617493035158_99485120'
            app/views/users/edit.html.erb:7:in `_app_views_users_edit_html_erb___747168809122195961_97933260'
            app/controllers/users_controller.rb:89:in `edit'
            test/integration/I18n_test.rb:218:in `block (2 levels) in <class:I18nTest>'
            test/integration/I18n_test.rb:204:in `each'
            test/integration/I18n_test.rb:204:in `block in <class:I18nTest>'

And a functional test failed:

ERROR["test_rejecting_malformated_email_while_updating_profile", #<Minitest::Reporters::Suite:0x000000001326bea8 @name="UsersControllerTest">, 63.357368742000006]
 test_rejecting_malformated_email_while_updating_profile#UsersControllerTest (63.36s)
Minitest::UnexpectedError:         ActionView::Template::Error: undefined method `errors' for nil:NilClass
            app/views/users/_edit_form.html.erb:5:in `block in _app_views_users__edit_form_html_erb___4035843046761948351_160617800'
            app/views/users/_edit_form.html.erb:2:in `_app_views_users__edit_form_html_erb___4035843046761948351_160617800'
            app/views/users/edit.html.erb:7:in `_app_views_users_edit_html_erb___3256878848318758383_160603060'
            app/controllers/users_controller.rb:72:in `update'
            test/functional/users_controller_test.rb:298:in `block in <class:UsersControllerTest>'

Both show ActionView::Template::Error: undefined method errors' for nil:NilClass` followed by a template line reference:

app/views/users/_edit_form.html.erb:5:inblock in _app_views_users__edit_form_html_erb___4035843046761948351_160617800'`

-- could we be using the wrong instance variable for the model? Let's take a look...

@@ -2,8 +2,15 @@
<%= form_for @user, :url => {:controller => 'users', :action => 'update'}, :html => {:class => "row",:id => 'edit-form' } do |f| %>
<%= hidden_field_tag "user[ui_update]", "true" %>
<div class="col-md-10">
<% if f.error_messages != "" %>
<div class="alert alert-danger"><%= f.error_messages %></div>
<% if @model.errors.any? %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! Yes, so here, the @model is a placeholder - we can replace it with @user and this should start to work! For all lines below as well. Sorry that was a bit ambiguous! This way it'll get the errors for the @user object.

Let's try that! Great work so far!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren Great thank you, looking through various files right now and I'm seeing I could have researched it further in users_controller.rb...

Just committed the corrections, looks like the tests are passing. Thanks again and let me know if there's anything else! 👍

@codeclimate
Copy link

codeclimate bot commented Oct 13, 2020

Code Climate has analyzed commit 745fc48 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! It worked!!! Great job!!

@jywarren jywarren merged commit a591541 into publiclab:main Oct 13, 2020
@welcome
Copy link

welcome bot commented Oct 13, 2020

Congrats on merging your first pull request! 🙌🎉⚡️
Your code will likely be published to PublicLab.org in the next few days, but first it will be published to https://stable.publiclab.org/ (it will take some minutes for this to load, and until then you may see logs from the build process). Please test out your work on this testing server and report back with a comment that all has gone well!
Do join our weekly check-in to share your this week goal and the awesome work you did 😃. Please find the link pinned in the issue section 📝
Now that you've completed this, you can help someone else take their first step!
Reach out to someone else working on theirs on Public Lab's code welcome page (where you'll now be featured as a recent contributor!). Thanks!

Help others take their first step

Now that you've merged your first pull request, you're the perfect person to help someone else out with this challenging first step. 🙌

https://code.publiclab.org

Try looking at this list of `first-timers-only` issues, and see if someone else is waiting for feedback, or even stuck! 😕

People often get stuck at the same steps, so you might be able to help someone get unstuck, or help lead them to some documentation that'd help. Reach out and be encouraging and friendly! 😄 🎉

Read about how to help support another newcomer here, or find other ways to offer mutual support here.

@noi5e noi5e deleted the feature/refactor-errors-edit-form branch October 13, 2020 21:35
@cesswairimu
Copy link
Collaborator

🎉

piyushswain pushed a commit to piyushswain/plots2 that referenced this pull request Oct 22, 2020
manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
ampwang pushed a commit to ampwang/plots2 that referenced this pull request Oct 26, 2021
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor error messages in Ruby on Rails forms to get rid of "dynamic_form" gem
3 participants