Mike Chilson

Joined

650 Experience
5 Lessons Completed
0 Questions Solved

Activity

Posted in Having issue with Nested routes and form

I know this is probably simple for most of you folks, but I am trying to work through an area I am weak on in Rails which is forms with nested routes. First here is what I have...

Models
Topic - has_many :blogs
Blog - belongs_to :topic

Nested Routes
resources :topics do
resources :blog
end

Blog controller edit and update methods

def edit
@page_title = " | Edit Post "
@blog = Blog.find(params[:id])
end

def update
respond_to do |format|
if @blog.update(blog_params)
format.html { redirect_to @blog, notice: 'Post was successfully updated.' }
else
format.html { render :edit }
end
end
end

I can get the form to load with the correct record I want by using the following though it feels clunky and most likely wrong.
edit_topic_blog_url(:id => blog.id, :topic_id => blog.topic_id)
which gives the URL
http://localhost:3000/topics/1/blog/25/edit

And my form I simply have
<%= form_for(@blog) do |f| %>
blah, blah, blah
<%end %>

However, after trying this I get the following error: "No route matches [PATCH] "/blog.dummy-article-title".

Can someone point me to a resource that explains the relationship between the form and nested route?

Thanks in advance!
Mike

Posted in Sharing Personal SAAS Tools...

Thanks, Chris. I really enjoy Go Rails and Remote Ruby. Keep up the AWESOME work you do for the Rails community.

Posted in Sharing Personal SAAS Tools...

Hi all, Wanted to take a moment and tell you about a couple of new sites I have published (really for my own use but hope others may find them helpful) using rails with a focus on privacy. This is what I love about rails.. Each of these only took about a day to build and publish. My plan is to make the open-source once I have had more time to go through and clean the code up some.

Web Address Guru - URL Shorter that doesn't cover you with ads.
https://webaddress.guru/

My Password Guru
https://mypassword.guru/

I hope to publish some other tools as I need them. Hope someone will find them useful.

Thanks guys.. Got it working tonight. You were right Monroe, once you get the nested routes working the Friendly ID was a snap to implement. Am very happy with what I ended up with. Thanks again!

Example post path: /forums/site-news/july-2020-news/

Thank you Monroe!

Hi Monroe, thank you for the kind offer. if you could post here when you have time I am sure it would help others as well. Many thanks! ~Mike

I would also love to see a tutorial on nested routes AND the friendly_id gem used together. I have been struggling through it and it's driving me nuts.