URL to Active Admin edit pages - ruby-on-rails

I'm developing a rails application that administers some data with Active Admin. One of my views exports a PDF that summarizes data in the back-end. I'd like to link each entry in the PDF to the "edit" view in Active Admin associated with that resource.
My question is how to get the URL to a specific Active Admin edit page for a model instance. I can't seem to find the URLs using rake routes or using other methods I found in the documentation.

For all the projects I've used activeadmin on, the edit routes have always been edit_admin_model, with a path that looks like /admin/model/:id/edit. Given this, I would expect your app to have an edit_admin_model_url(model_id) for each model you have an ActiveAdmin file for, that you could use in a link helper when compiling your PDF.
If that doesn't help, could you post the output to rake routes for us?

Related

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.

How to find spree account view source code

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

Find url for webpage based on a partial file

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.

rails how to generate a http link connect to some path without knowing current domain at backend

For example, I dont know my website name yet, it can be www.abc.com or www.xyz.com
And I want to send a email to my users with the link
www.abc.com/controller1/id/path
or
www.xyz.com/controller1/id/path
How I setup this on rails ???
It doesn't really matter what the hostname of your app is when using the right helper, rails will generate either relative paths or absolute paths for links at runtime (depending on the helper used). url_for is one such helper, link_to is another. Any route that is defined in routes.rb, you get a helper for it. Try looking at the output from rake routes, you'll see which url helpers may already be defined. Just add _path to the routes you see listed in the first column to get a relative path url. For more info on routing see the Rails Guide.

Rails create admin controller and view in other directory and with own style

I need to do own administration logic, with it's controllers, view etc... ActiveAdmin and so over are not good for me. But how can i do this in other directory (for example controllers/admin/). How to write then rails g command? (view must be in folder admin too). Also how to connect twitter bootstrap only for admin controllers?
Have a look at this link, where they use the same admin subdirectory grouping (link broken) example. The example is for an older version of Rails, but should be relatively valid for Rails 3.2.
Edit: See this namespaces question.
rails generate controller admin/Users
For bootstrap, just don't use the bootstrap specific id/class attributes in your admin stylesheet.

Resources