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

Fixes the paths for generated views #221

Closed
wants to merge 1 commit into from
Closed

Fixes the paths for generated views #221

wants to merge 1 commit into from

Conversation

5minpause
Copy link
Contributor

Fixes #202.

Problem:

The documentation correctly states that view generated via rails g administrate:views should live under
app/views/administrate/application/. The generatator puts them under
app/views/admin/applications/ though.

Solution:

The methods that create the paths need to be adapted.

Nota bene:

While running the tests, the first arg for the generator is empty. When
the generator is run inside a project, the first arg is application.
This leads to the view paths having applications instead of
application. This commit fixes this as well.

expected_contents = contents_for_application_template("show")

run_generator []
contents = File.read(file("app/views/admin/application/show.html.erb"))
contents = File.read(file("app/views/administrate/application/show.html.erb"))

Choose a reason for hiding this comment

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

Line is too long. [84/80]

@5minpause
Copy link
Contributor Author

How would you like me to handle the long lines?

@c-lliope
Copy link
Contributor

Based on conversation on #202, I think we can switch back to admin/ instead of administrate/. That should get rid of most of the line length warnings.

@5minpause do you want to update this to revert to admin/? I can pick this up in another PR today if that's easier.

@5minpause
Copy link
Contributor Author

I gladly update this pull request. It's evening here, so you'll get this tomorrow.

Am 12.11.2015 um 20:05 schrieb Grayson Wright notifications@github.com:

Based on conversation on #202, I think we can switch back to admin/ instead of administrate/. That should get rid of most of the line length warnings.

@5minpause do you want to update this to revert to admin/? I can pick this up in another PR today if that's easier.


Reply to this email directly or view it on GitHub.

@c-lliope c-lliope added the ready label Nov 12, 2015
@c-lliope c-lliope added this to the v0.1.2 milestone Nov 12, 2015
@5minpause
Copy link
Contributor Author

@Graysonwright I updated the commit and reverted back to /admin. The thing about /applications//application remains.

@@ -21,7 +21,8 @@ def copy_resource_template(template_name)
end

def resource_path
args.first.try(:underscore).try(:pluralize) || "application"
return "application" if args.none? || args.first == "application"
args.first.try(:underscore).try(:pluralize)
Copy link
Contributor

Choose a reason for hiding this comment

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

Our style guide says to avoid conditional modifiers (lines that end with conditionals). Can we re-phrase this as:

if args.none? || args.first == "application"
  "application"
else
  args.first.underscore.pluralize
end

Also, I think we can ditch the try() methods, because we now know that args.first is defined at this point.

@c-lliope
Copy link
Contributor

Left a comment - other than that, looks good!

@5minpause
Copy link
Contributor Author

Oh I wasn't aware of this rule in your style guide. Thanks for pointing this out. Let me update the commit.

Problem:
The documentation correctly states that view generated via `rails g
administrate:views` should live under
`app/views/admin/application/`. The generatator puts them under
`app/views/admin/applications/` though. References #202.

Solution:
The method that creates the path needs to be adapted.
@5minpause
Copy link
Contributor Author

@Graysonwright I updated the pull request according to the style guide. Thanks for making me aware of it.

@c-lliope
Copy link
Contributor

Sorry for the hold-up here. I want to pull this branch down locally and see if I can come up with tests for it.

Implementation looks good, though.

@c-lliope
Copy link
Contributor

I hate to draw out the discussion on this more, but after looking at it closer I'm not sure this change is as simple as it first appeared. Here's my thinking:

Breaking down the problem

The problem is that the generator is placing the files in app/views/admin/applications instead of app/views/admin/appliction.

This happens when the user types:

rails generate adminsitrate:views application

However, the documentation states that if you want to generate views that apply to all resources, you should run:

rails generate administrate:views

...without the application at the end.

This is a subtle distinction, but it changes this issue from a bug report to a feature request. As long as users follow the docs, the generators will work fine for them. So instead of fixing broken behavior, this PR would essentially be auto-correcting people's mis-use of the generator API.

The new question

Our new question is: if users mistakenly type application at the end of their generator string, should we assume that they want to generate the views at the application level?

There's an obvious reason to do so - we've already had at least one user confused by this, and it has the potential to help people avoid a frustrating-to-track-down error.

On the other hand, imagine that someone's writing a Rails app that processes job applications, and they have a model named Application. In that case, the correct place to generate the views for that model would be in app/views/admin/application. This PR would remove our ability to do that, and would result in another frustrating-to-track-down error in that application.

So, thoughts on the tradeoff?

@c-lliope
Copy link
Contributor

I'm closing due to inactivity. If we get more requests for this, I'll gladly re-open.

@c-lliope c-lliope closed this Dec 21, 2015
@c-lliope c-lliope removed the ready label Dec 21, 2015
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.

Generating views creates wrong file paths
3 participants