How to find spree account view source code - ruby-on-rails

recently I had a need to modify a view template of the Spree e-commerce. According to the guides, I need to run bundle show spree to view current location of the spree gem and then copy view templates from there. https://guides.spreecommerce.com/developer/view.html But the target folder does not contain views folder << account >>, also I did a search for particular word 'favourites', no results. Maybe I need to install other gem, like spree_frontend or other? Can someone please help to find views to change?

I am not familiar with Spree but it looks like you're supposed to write/customize your own template using Deface. There is no "account" file in the source tree. To search go to their github, click the backend directory, click "Find file" and enter "account"... seems there are no results.
Later edit: you might want to look at these templates here:
https://github.com/spree/spree/tree/master/backend/app/views/spree/admin/users
I think one of them is used for the "account" method. If you're trying to edit the admin account edit page for instance, it's the users/edit.html.erb template.

If you are using devise with spree you want to look for account and auth related views to override in spree auth devise gem views
https://github.com/spree/spree_auth_devise/tree/master/lib/views

Related

What is the process for locating any given gem's built-in scaffolding templates?

I'm tweaking some scaffold templates for an app so I mostly just want to copy the built-in/default templates. My question is what is the process I can follow to locate the templates?
For example, thanks to the helpful answers of Tim Krins I now know to look in:
cd $(bundle show railties)/lib/rails/generators/rails/scaffold_controller/templates/ for controller templates (reference)
cd $(bundle show activerecord)/lib/rails/generators/active_record/model/templates/ for model templates (reference)
I also managed to combine his bundle show <gem> tip with spelunking through Github issues in haml-rails to figure out the path for HAML templates is:
cd $(bundle show haml-rails)/lib/generators/haml/scaffold/templates
I haven't yet been able to use that knowledge to figure out the general solution though so next time I'll have to search StackOverflow again.
How would I go about figuring out for myself the template locations for various test files (without telling you which testing framework I'm using)? How would I locate the templates used for the invoke resource_route step?
How do I figure out which gem to look in? (e.g. How could I have figured out railties vs activerecord above?)
How do I figure out what path to look in? (e.g. How would I know to look in activerecord/.../activerecord but railties/.../rails?)
Which gem are you trying to change?
What is needed in the case of the Devise or Spree gems is to recreate the filepath within the app directory, then copy/clone the erb/haml file from the gem's github repo, and make your changes in the local file.
There is a gem called Deface which can allow you to edit specific html components in views without recreating the entire view. This is a more complex but ultimately more maintainable path - depending on the extent of your changes.

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.

Creating a gem for cells components

I want to create UI components to enable users to edit data present in a specified structure. I decided to give Cells a try, but I need to encapsulate the whole code in a gem, since I want to provide this components as an extension to an existing gem (criteria_operator), which is the source of the classes used for the data.
Is this possible? And if yes, how do I start? Normally, cells expects you to create views and models in specific folders of the default rails folder structure. When creating a gem, I only have the lib folder...
If you need any additional information, please just point it out in the comments. I wasn't sure if there is anything useful I could provide.
Disclaimer: The gem mentioned was created by me, and this question isn't intended to promote it.
To use another gem- criteria_operator, just add it to your gemspec:
s.add_runtime_dependency('gem_name', '~> <version>')
or add it to your gems's Gemfile.
To have models and views in your gem, you can use rails engine.
Rails engine allow you to wrap a specific Rails application or subset of it inside a gem.

Overriding the default views in RailsAdmin

I am using Ruby on Rails 4.2.1 with RailsAdmin. The gem works excellent, but I have the requirement that the layout of the admin panel and the forms must look different than what is generated by default. For example, the navigation should be horizontal top, the forms should order the fields in two columns.
So far I haven't find a way to copy the views locally and modify them (like in Devise for example). I have tried to replicate the views manually in the respective path under my views folder by copying the original views, but I got problems with the helper methods that are part of RailsAdmin not being accessible from my views.
I dug deeper and found that there is a task copy_views, it was referred to in questions for the older versions of the gem, but if I try to use it now rake rails_admin:copy_views, it is not available anymore.
Am I doing something wrong, or is there another way to do this?
You can create folders in your app
app/views/rails_admin/main for https://github.com/sferik/rails_admin/tree/master/app/views/rails_admin/main
app/views/layouts/rails_admin/ for
https://github.com/sferik/rails_admin/tree/master/app/views/layouts/rails_admin
Put modified files there. It can get a little messy and you will need to update the files if the gem changes.

How to replace a Template using Deface

I'm new to rails and I've set up a standard spree e commerce solution. I now want to customize the default templates and styles. According to the spree documentation [1], the best way to do so is using Deface. Unfortunately, I can't figure out the location of the existing views/layouts.
For example, while the document suggests:
For example, to override the main layout, create the file YOUR_SITE_OR_EXTENSION/app/views/spree/layouts/spree_application.html.erb
my app/views folder doesn't contain a folder called spree
Can anybody tell me, how to change the view templates?
Thank you.
[1] https://guides.spreecommerce.com/developer/view.html
You have to actually create that directory and every directory along the way until you reach the file you wish to override. If you run these commands from your root directory you should be good to go.
mkdir app/views/spree
mkdir app/views/spree/layouts
touch app/views/spree/layouts/application.html.erb
Then copy the content from here: https://github.com/spree/spree/blob/master/frontend/app/views/spree/layouts/spree_application.html.erb into the file you've just created.
If you restart your web server you should be able to make changes to the local application.html.erb file and see them locally.
Any time you want to override a template completely, you can find the template you need to override on Github: https://github.com/spree/spree and recreate the necessary files/directories. Spree will look for templates in on localhost before the gem, so as long as you override the right template in the right directory, you can customize any view you like.
Alternatively, you can try running the rails generate spree:frontend:copy_views command to pull all the views you need from gems, and anything that is missing can be added manually, in strict accordance with the gems folder hierarchy. For example, in gems is parsl in the following spree_backend/views/spree/admin/users/_lifetime_stats.html.erb. To enter the desired code, I have to make a folder on the following path - the name of the project/app/views/spree/admin/users/_lifetime_stats.html.the erb and all the changes I will make here will fall into the main view code. This is an alternative to Deface::override

Resources