No Template for interactive request rails - ruby-on-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.

Related

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.

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

Ruby on Rails generating controller with existing folder

I'm really new at this and I don't want to mess up my current application. I'm currently working on HTML/CSS stuff but I have a little understanding as to how to get things working.
I created a new controller by just doing
rails generate controller sign_up
I've created a index file (index.html.erb) inside sign_up folder from rails that automatically generated. Now I wanted to add more files, can I just add more files by typing in
rails generate controller sign_up send_page more_page other_pages
Will send_page, more_page, other_pages be automatically combined into the existing sign_up folder? Is this the correct way of adding pages if I want rails to add other files automatically? I just want it to ruin what I have so far so I don't want to try it for myself because I'm still really new to this,
Thanks!
To answer your question :
New files will be added to the existing folder but existing files will not be merged, you'll have to resolve the conflict by choosing between old and new files.
It seems to me you're trying to use generators for every action you need in your app :
Scaffolding is great to have a sample structure, but as soon as you start building your controller for real you need to move away from it : extend the controllers, models and views by hand. It's the only way you'll start to really understand how things are working.
If you run the generator again, it's going to complain about conflicts with existing files. Then you'll have to choose to overwrite (losing your existing changes to e.g. the controller), or not (in which case you won't get the new auto-generated methods, etc.).
You can just create a new controller action and a new view for each additional page you want to add (and a unit test, of course!). If you're using non-standard/non-restful action names, you'll also have to edit config/routes.rb to route them.
Looking at the names in your example, and your reference to "pages", I suspect what you really may want to do is create separate controllers for send_page and more_page. If that's the case, you'd run the generator separately for each new controller.

Resources