Find url for webpage based on a partial file - ruby-on-rails

I was introduced to a large team and not very familiar with the site I am developing for. I need to make an edit to a partial (i.e. _partial_file.html.haml) and need to verify the change visually but I don't know where that partial is being displayed on the website. Is there a way I can get a url from a partial file with rails.
For example, could I run a rake routes | grep or do something in the rails console to help find any URL where the partial is displayed?
Thanks

If I understand you correctly. While in your rails app root.
grep -r "partial_file" .
This will allow you to look for instances of partial_file and where it's being rendered. You might see it in a view or a controller. Depending on where you find it, you can rake routes and see just what url you should enter to see your output

When you render a page you should see output in the console for all templates being rendered.
example rendering template show.html.haml from SomeController#index
Use this to locate the template that is including your partial. You can then use that to search the entire project for all templates including that partial.
Rails renders templates by a specific convention that maps controller methods to specific layouts and templates. I would familiarize yourself with http://guides.rubyonrails.org/layouts_and_rendering.html to get a better idea of how the default internals work for you rails app and use that as a starting point.

Related

No Template for interactive request rails

Trying to add one route and respective controllers and views but getting error.
Tried with adding erb file in views folder.
Hard to diagnose with the little information you’ve provided, but given this statement:
Tried with adding erb file in views folder
It sounds like you’ve place your index.html.erb which corresponds to your MainController directly in your views folder.
Rails expects this to be located within a folder that reflects the controllers name. Ie views/main
I recommend checking out the official documentation to learn more about how everything flows.

In Ruby on Rails is there a way to put the path of every partial in an HTML comment?

I work on apps that often have thousands of partials and finding what partial is rendering a section of HTML can be tedious and just waste time.
In development mode, it would sometimes be very helpful to turn on a config to have every partial used be prefaced with its path in an HTML comment so I could quickly know how to access and edit it.
Is there a config option for this or a gem that someone has made for this?
This functionality is built-in to recent rails versions for erb templates.
See here for details: https://blog.saeloun.com/2020/05/11/rails-support-annotates-html-output-with-template-file-names.html
That page mentions another option you could try.
Here is a link to the rails pr that introduced the change: https://github.com/rails/rails/pull/38848

Editing UI of Samvera Hyrax

I wanted to customize the UI of Samvera Hyrax application and I've built a HTML template. Now, I want to replace the old UI with the content of my HTML files, when I say it on github I found view files where I can edit the application to implement my design. But after installing I could not find any files under views. Though I found application.html.erb.
I cannot figure out where <%= yeild %> has been pointing and when I replaced all the content with my home page code. It made no changes in the hyrax working.
Thanks in advance.
Assuming you followed the Hyrax installation procedure detailed on the github wiki here, what you'll notice looking at your routes in config/routes.rb is that Hyrax is mounted as a rails engine. So using the template you didn't clone Hyrax, but you created a new rails app that uses Hyrax as an Engine. If you haven't used Engines before, it may be worth reading up on them here. This is why you don't see all the views from the Hyrax project in the application you've generated using their template.
You can override views from the Engine by creating the view in your own project in the same path as it is in Hyrax. You may want to do some additional digging to determine if this is a path you really want to go down, as it can get complicated to maintain overridden views, and there may be alternative strategies that can accomplish some of what you want to do with CSS or themeing within Hyrax. It may depend on how much you want to override and how custom a theme you are trying to achieve.

Editing page views with Irwi Wiki gem in Rails

What's the best way to edit and format page views using Irwi Wiki in Rails?
Here is the controller it's set up for me:
class WikiPagesController < ApplicationController
acts_as_wiki_pages_controller
end
Though there's no views folder corresponding to the controller. I just want to be able to edit the html or add css to the wiki articles I can create now.
https://github.com/alno/irwi
As it says in the docs:
You may create your own templates for controller actions (show, edit and history), in other case default built-in templates will be used.
So, in your views folder, create a folder called wiki_pages and then put your new templates in that folder.
Here's what's going on:
When your WikiPagesController currently goes to render a wiki page, it looks for a template in apps/views/wiki_page corresponding to the current action. That folder/file doesn't exist, so it looks in other directories and ultimately finds the template in the gem. (You should be able to see this process in your console.)
When you create the folder and add the template (as above), the WikiPagesController finds the template in your application and renders that, instead of rendering the template provided by the gem.
So I have done a little research and I think you can just copy all files from here: https://github.com/alno/irwi/tree/master/app/views/base_wiki_pages into views/wiki_pages folder so you will have all views locally and you will be able to edit them.

Change Rails Scaffold Naming Scheme

I'm a happy user of RoR but have one complaint. When I do script/generate scaffold it automatically generates all my files and places them in their proper folders. However, all the different scaffolds I've created name their view files the same.
I have a bunch of index.html.erb view files and when I have them open in my text editor, it's almost impossible to tell what controller they're related to.
I'd like to change the default naming scheme of the scaffold command to name the individual files to contain their view folder name. So, instead of index.html.erb, use index.home.html.
Is there a way to do this, or am I stuck? What solutions to the multiple files with the same name problem have you Rails developers discovered?
Thanks!
You're going to be fighting the Rails' conventions by going down that path and Rails works best when you work with it rather than against it. A core part of the philosophy of Rails is that there are a set of conventions that once learned make it easy to find your way around any Rails application.
Instead of trying to redefine how Rails works, I would recommend taking advantage of the features offered by your text editor or IDE for quickly navigating to the correct view template. For example, the Rails bundle within TextMate on the Mac lets you quickly open the view file associated with a particular model and there's a plugin for Vim that provides an equivalent feature.

Resources