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
Refactoring profile.html.erb code pt. 3 #4339
Comments
@sashadev-sky I don't think this should be a |
@oorjitchowdhary I have been getting mixed reviews so I will wait for @jywarren @gauravano to review. I can rewrite it based on the tags they add! But I partially agree with you it's on the fence. Maybe I can make it even simpler |
@sashadev-sky this is properly formatted but I am afraid whether a newcomer can deal with such huge PR or not. We want the first experience with Public Lab will be friendly and very less time-consuming. Collaborators should not be dishearted with any errors or bugs they would get in the PR. I agree with @oorjitchowdhary. |
done! @SidharthBansal @oorjitchowdhary |
We can also divide this issue in 3 FTO's, corresponding to 3 blocks as explained by @sashadev-sky. What do you think @sashadev-sky, want to open 3 FTO's? Nice work 🎈 😃 ! |
@gauravano Sure! What if I leave the first one that has the extra conditional as a help wanted, and make the two simpler ones FTOs? |
Yes, sounds good! |
Also, both FTO's would depend on 1st block, so I think either we can wait for someone to claim this one or we could add a function ourselves. Thoughs? |
@gauravano you are very right. I can just solve this one myself right now, then rewrite the other two. |
Looking for your PR 😃 |
@gauravano just making sure you saw the PR #4343 I tagged you in |
Sorry, i am away from lappy right now. I would review in some hours.
Gaurav Sachdeva
…On Thu 20 Dec, 2018, 5:06 AM Sasha Boginsky ***@***.*** wrote:
@gauravano <https://github.com/gauravano> just making sure you saw the PR
#4343 <#4343> I tagged you in
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4339 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AT6S9ty76Vr2iI9rS3D0lrs5LWpZubk9ks5u6s2WgaJpZM4ZaqHH>
.
|
The problem
Our code in
app/views/users/profile.html.erb
is very verbose... we could use some refactoringWe can start by refactoring out a reoccuring line from the code. For now, the 1st line of:
plots2/app/views/users/profile.html.erb
Lines 237 to 242 in 1931439
Solution
What to change it to:
Code that we want to refactor and that might be useful to multiple views in the future can go in the
app/controllers/application_controller.rb
Try adding a
current_profile_user
method to the application controller. We can move the conditional to check if there is a current_user and if the current_user is the user who owns the current profile we are viewing with a method like so:Add your new
current_profile_user
method to the helper_methods at the top of the page so that it is available to all our views:plots2/app/controllers/application_controller.rb
Line 6 in 1931439
Refactor the lines in the 3 code blocks found in the "The Problem" section to use your new helper method instead.
Note that the 1st code block has an additional check for current_user.can_moderate? in it which we need to add on.
For ex., that line can be updated to
<% if current_profile_user && current_user.can_moderate? %>
Thanks!!
Steps to Fix
commit your changes to your branch and start a pull request (see contributing to Public Lab software) but mark it as "in progress" if you have questions or if you haven't finished
💬 Get help
If you need any help - here are some options:
Next Steps
When you're done and the code is merged, if you see other places in the code that could use this refactoring, open up another first-timers-only issue and walk a new contributor through it :)
Note related issues #4342 and #4341
The text was updated successfully, but these errors were encountered: