Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:56:19+00:00 2026-05-31T11:56:19+00:00

I am creating an app using Ruby on Rails and in the Admin panel

  • 0

I am creating an app using Ruby on Rails and in the Admin panel there are blogs and posts controllers. The routes for the admin area looks like this:

constraints :subdomain => "admin" do
  scope :module => "admin" do
    root to: "pages#index"
    resources :blogs do
      resources :posts, :controller => "posts"
    end
  end
end

What I have is http://admin.mydomain.com/blogs showing the blogs with /blogs/2/ showing the posts on that blog.

What I want is for when creating a new post at /blogs/2/posts/new that the blog_id is attached to the post.

In the admin/posts_controller.rb I have this as the create action

def create
  @post = Post.new(params[:post])

  if @post.save
    redirect_to posts_path, notice: 'Post was successfully created.'
  else
    render action: "new"
  end
end

At the moment it just creates a post. I want to link that post to the current blog id which is in the URL – /blog/2.

How would I go about doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:56:20+00:00Added an answer on May 31, 2026 at 11:56 am

    There are a number of ways of doing this and does depend on how you’re actually using the controller. If you just edit posts at /blogs/1/xxxx then you can do this:

    The blog_id will be available as params[:blog_id]. I’d usually create a before_filter to find the blog and then do the rest in the create action:

    before_filter do
      @blog = Blog.find(params[:blog_id])
    end
    
    def create
      @post = @blog.posts.build(params[:post])
      if @post.save
        redirect_to [@blog, @post], notice: 'Post created successfully'
      else
        render :action => 'new'
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if yes, is there a tutorial available for creating an android app using the
I am creating a web app using Ruby and Sinatra, and I'm splitting up
I am using the Evernote gem in my Ruby on Rails app. I am
I'm using the Ruby oauth-plugin (version 0.4.0.pre7) to make my Rails (3.0.3) app an
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
I'm creating a Ruby on Rails app that consists of stories. Each story has
I'm busy creating a very simplistic ruby on rails app that won't need a
I am working on creating a adserver using rails 3.1 and ruby 1.9.2. In
I am creating a WPF app using MVVM. The app manages tagged documents, called
I'm creating a WPF app using the MVVM design pattern, and I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.