How can I edit routes.rb in runtime dynamically from rails app? - ruby-on-rails

I have a situation that I needed to edit routes.rb from rails app progammatically. Need an idea how to do it. I am rails beginner.

When you change something in "routes.rb" you must restart app, so It is very bad idea. You can do with one controller/route. This controller can redirect to some other other controller or do something so you can use ONE ROUTE in routes.rb. You can write some your code here and We will help you.

Related

Rails App inside a Rails app's sub-folder

I have a rails app, but a client wants to have another rails app be hosted in a ssub-folder of the first rails app.
I can't find any help on how to do this or if it's possible, because if I go to:
http://example.com/second_app, the first app will try and route it despite another app being situated in the second_app folder.
I hope this makes sense, and someone will be able to help.
Sorry, two Rails apps with one inside the other is not possible.
If all you want is a special page for the client, you need a view, controller, and route:
$ rails g controller Pages second_page
And then change your route (config/routes.rb) from get 'pages/second_page’ to get '/second_page’.
After starting up your rails s, you can then go to localhost:3000/second_page and see your page.
If I’m completely misunderstanding what you’re trying to do, please describe your situation a bit more and I’d be happy to help.

where are the auto generated routes in rails scaffolding?

Alright, I'm starting to learn rails and so far im really turned off by how much is auto generated and happening behind the scenes without me knowing. I generated scaffolding for posts. and it auto created routes allowing me to edit and see posts (/posts, /posts/:id/edit, /posts/:id/show....etc) When I go into config/routes.rb I see absolutely no mention of these routes. even though they work. Where are these routes? and where can I add custom routes if the ones for the controller are not in routes.rb?
When you run rails generate scaffold post, rails will generate models, controllers, tests, routes, stylesheets etc.
Rails tells you what files it just generated, you can see it in terminal.
In routes.rb there will be a line
resources :post, this is a shorthand for all RESTful actions that were generated in the controller.
You can declare custom routes in the routes.rb file. I.e.:
get 'my_path'=> 'my_controller#my_action'
In General, Rails can do a lot of stuff for you, and you can avoid repeating default behaviour over and over again. But you can also do most stuff yourself, without Rails magic.
Instead of using scaffolds, just run rails generate controller controller_name action1 action2 (..). You'll end up with just a controller, no automatic views, no automatic model etc.
Or you can just create all files and register your components yourself.
The Rails Guides are a good starting point for understanding the magic.

Blogit is not routing in rails 4

Hi guys,
I have just installed blogit into my Rails 4 application. When I go to /blog I get routing error of every single route I have got. I get "undefined local variable or method". It is like that it won't load my routes at all.
Not sure if it make sense though. Please let me know what you want me to put here so you guys can have a look.
I have current_user defined in ApplicationController.
In the installation what I didn't understand is "declare which of your models acts as blogger in your app". That might be the issue.
Thanks in advance.
In case someone is looking for this.
Answer trail is in here. It is Explained fully
So just to sum it up, I added main_app to all of the links in the view and all are good.
Basically when you are in the /blog you will be in the engine, and you need to tell the app the correct path. Thanks to emaxon.

My delete button stopped working

As I was building the app I get this error.
Unknown action
The action 'destroy' could not be found for UsersController
The problem I have is that I do have a destroy method in my users controller and the button was working just fine. It just decided to stop working all of a sudden.
I started coding in a mailer and that is when it stopped working. Let me know what code you would like to see.
Appreciate the help.
Suppose that web server restart didnt help...
Maybe you should check your routes... Do you have
resources :users
in routes.rb file? If so, could you show us the whole content of that file?

Rails and a development domain

I'm trying to use http://ls1.bigseapreview.com as a domain for a Rails project. The problem is it doesn't seem to be correctly mapping any routing apart from the home page.
I have added /about but you can see that you will just get a 404, but it works locally.
What do I have to do to fix this?
Can you add your routing file?
+I added /about and it looks like it's working
Are you sure that this is a Rails project? Your "about" link points to "/about.php".

Resources