r/rails•
Magnomious

same-page dynamic content?

Me: Rails novice, started with ruby for a couple months, then a quick crash course in html/javascript, and now just learning as much rails as i can currently.

I currently have a blog, (http://rehan-blog.herokuapp.com/) - and on the right I have a 'Todo' section. Currently just text.

I have a Todo app built separately, but it currently has the different paths (/new,/create,/edit, etc). What i would like is to be able to create, edit, delete, etc., on that blog page directly, inside that Todo section area, instead of being sent to different pages.

Would appreciate being pointed in the right direction with how to achieve this, not sure what to google or look for specifically to achieve this with rails.

Posted Mar 21, 2017, 4:53 AM UTC

64
JimmyPopp•

The easier way would be to make it a form. Google rails form helpers. Nice work! Keep with it

1
ainus•

I just started trying out the react-rails gem, which would probably be suited for this project.

You could port your existing Todo app to react using react-rails and instead of redirecting to the /new, /create, /edit pages you handle those transactions via ajax.

I found this tutorial very helpful for creating a simple CRUD app with react-rails.

1
MagnomiousOP•

Thanks, I used a similar tutorial using AJAX (http://roseweixel.github.io/blog/2015/07/05/integrating-ajax-and-rails-a-simple-todo-list-app/).

I got everything functioning, and now trying to integrate it to my blog: the question that has arised for me: I have a 'todos_controller', with its own View, with an index/create.js.erb/destroy.js.erb etc.

I have an 'articles_controller' for my blog page, with the index etc. So I go to the index.html.erb of my ARTICLES controller, and put in the form info for my Todolist, but that Articles (index.html.erb) is asscoiated with a different controller. And my initialization for my Todo is initialized in a seperate todo_controller.

TL;DR, How do I share two controllers with 1 view?

1
skyksandr•

I'll recommend take a look on rails remote forms and remote links. Article from DHH: https://signalvnoise.com/posts/3697-server-generated-javascript-responses

I'm using it on my hobby project and it is great approach. I'm personally don't know why it is not so popular as it's deserved.

1