Routing Error - Switching Index File in Rails - Bootstrap Theme Implementation - ruby-on-rails

I am trying to implement a bootstrap theme in my rails app I just created.
First I created new project with Rails new scaffold, and created a database. the Index page worked fine, showing a table of the database content. (I am using this tutorial to go through it:https://launchschool.com/blog/integrating-rails-and-bootstrap-part-1)
However, as I try to implement the bootstrap theme, I am running into an issue. I read from another tutorial to manually copy and paste the contents of the bootstrap theme over to my apps corresponding folders. My goal is to copy the bootstrap's template index.html file over, so that I can start from there.
I am trying to replace the default index.html.erb file with the index.html file that came with my bootstrap theme. So I copy the file, rename it to match the original file. Then remove the original index html file. But when I do this my routing won't work. I get the routing error listed below.
What do I do? If I put the old index file pack in the views it works again. But when I try to switch it stops working.
I get this error when trying to load the page:
Routing Error
No route matches [GET] "/index"
Rails.root: /Users/../code/lettersTest3

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.

why changes to layout application.html.erb view does not show on new Rails 6 app

Upon scaffolding a new Rails 6 app, I see the Yay! You’re on Rails! page. When making changes to application.html.erb, I'm not seeing the changes being reflected. I was wondering how to fix this.
Because that is a static page.
What happens is that the yay you're in rails is a static page that is located on the rails gem, you can check that by looking through the logs of your server, mine for example is located here /Users/jean/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.2/lib/rails/templates/rails/welcome/index.html.erb
In order to override you need to create a default root page in your routes.rb with the respective controller and view. That will use your application.html.erb as the default template.
For example you can create a home controller
rails g controller Home index
That will generate a bunch of files including the view file and the controller file, now you have to go to your routes, remove the route generated and add this:
root 'home#index'
Now if you start the server again you will be able to see the correct layout (application.html.erb) that you changed plus the content of the newly generated index.html.erb located in app/views/home.

Rails 4 Route "match" changes the CSS/JS base URL on template

I'm making a blog system for my Rails application and I'm stuck with this problem a while and don't know what's going on with my routes.
I installed a template for my app and all the css/js/images files from this template are in "public/" not in the assets folder. It was the only way I found to make the template working.
My blog system have this routes:
When I access "/blog" it serves the index view and it loads all the assets from "assets" and "public". But when I try to access "/blog/" or the matched route "/blog/category_slug/post_slug" rails tries to load the files from "public/" with this URL:
"base_url/blog/category_slug" and that's really weird!
I'm current using Rails 4.0.2. Any thoughts?
Fixed the problem adding a "/" before the path to the assets:
From: "css/bootstrap.css"
To: "/css/bootstrap.css"
I still don't know why this only happens in the blog controller, but that worked.
Thanks.

Can I Identify The Environment Using HTML Code?

I just figured out how to create custom error pages in the public folder using I18n. Those error pages have links that will return the user to a page in the application such as the home page.
When my application was running 3.2.13 I had the custom error pages in the app folder using config.exceptions_app = self.routes in application.rb. When I had that code all I had to do was use a link_to statement pointing to the route I wanted the user to return to. If I was in the development environment it would go to http://localhost:3000/somelink and in production it would go to http://myrailsapp.com/somelink. I replaced these with the ones in the public folder after rewriting them in Rails 4 because it appears that config.exceptions_app = self.routes is ignored in Rails 4.
My error pages in the public folder are html, not html.erb so there is no ruby/rails code. I would like to replicate what I had previously where I can check the environment in my error pages and point to localhost for development or my domain URL for production. I currently have code in my error page similar to this:
My Link Text
I'm definitely open to changing these to html.erb files. I initially thought about that but from my research and trying what I found nothing is working for Rails 4.
Any help would be appreciated.
You don't need any "autodetection" in html, just cut the domain part from the url and use a local path instead.
Just change http://myrailsapp.com/en/home to /en/home.
And yes, you do need the opening slash to be independent from the current_url in your link.

How can I combine the front end code in /public with back end code in /apps

I'm new to rails, and created a simple bootstrap site and put it all under /public folder.
Now I wanted to make a contact form so I followed this tutorial and made a simple rails app.
My question is, following the tutorial the contact form UI created is in /app/views, which does not have the same styling as my bootstrap UI. Is there a why for me to create a form in the /public htmls and call some of the function in the rails backend?

Resources