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 9064675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:18:51+00:00 2026-06-16T16:18:51+00:00

First of all, My resource is nested using to_param for slug at Community model.

  • 0

First of all, My resource is nested using to_param for slug at Community model.

I’m at example.com/shop/walmart/topic/14/edit .
If I press update without captcha input, it obviously should take me back to edit page again with flash error message.
However it takes me to example.com/shop/14/topic/14/edit . <= it’s taking the same parameter. it should take ‘walmart’ which is community_name for first argument, and :id for topic.
All the fields are set the same with what I typed in at the previous page.
How can I avoid this? it should redirect to the same url as previous page.

routes.rb

resources :communities, :path => "shops", do
    resources :community_topics, :path => "topics"      
end

controller

def simple_captcha_check
    if !simple_captcha_valid?
        flash[:error] = 'Wrong Captcha!'

        if request.put? # We came from an edit request
          @community_topic = CommunityTopic.find(params[:id])
          @community_topic.attributes = params[:community_topic]
          render :action => :edit
        elsif request.post? # We came from a new request
          @community_topic = CommunityTopic.new params[:community_topic]
          render :action => :new
        end

    end
end

models/community.rb Note that I use slug here

def to_param
  "#{community_name}"
end

views/community_topics/_form.html.erb

<%= form_for @community_topic, :html => { :class => 'form-horizontal' } do |f| %>
  <div class="control-group">
    <%= f.label :title, :class => 'control-label' %>
    <div class="controls">
      <%= f.text_field :title, :class => 'text_field' %>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :body, :class => 'control-label' %>
    <div class="controls">
      <%= f.text_area :body, :class => 'text_area' %>
    </div>
  </div>

    <div class="control-group">
      <div class="controls">
  <%= show_simple_captcha(:label => "human authentication") %>
    </div>
  </div>



  <div class="form-actions">
    <%= f.submit nil, :class => 'btn btn-primary' %>
    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                community_topic_index_path, :class => 'btn' %>
  </div>
<% end %>

rake routes | grep community_topic

      community_community_topics GET    /shops/:community_id/topics(.:format)          community_topics#index
                                 POST   /shops/:community_id/topics(.:format)          community_topics#create
   new_community_community_topic GET    /shops/:community_id/topics/new(.:format)      community_topics#new
  edit_community_community_topic GET    /shops/:community_id/topics/:id/edit(.:format) community_topics#edit
       community_community_topic GET    /shops/:community_id/topics/:id(.:format)      community_topics#show
                                 PUT    /shops/:community_id/topics/:id(.:format)      community_topics#update
                                 DELETE /shops/:community_id/topics/:id(.:format)      community_topics#destroy

By the way, my index action in controller is just like this, and it’s working fine!

community_topics_controller.rb #index

  def index
    @community = Community.find_by_community_name(params[:community_id])
    @community_topics = @community.community_topics

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @community_topics }
    end
  end
  • 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-06-16T16:18:52+00:00Added an answer on June 16, 2026 at 4:18 pm

    I don’t see your controller actions, and don’t know names of variables, but anyway in case of nested routes you have to define all urls precisely with named routes, or with polymorphic helper (as i do).

    So your form helper must be looking as next:

    <%= form_for([@community, @community_topic], :html => { :class => 'form-horizontal' }) do |f| %>
    

    it have to send request to /shop/walmart/topic/14/update (or ‘new’ if @community_topic is a new record)

    community.rb:

    you can just
    
    def to_param
      community_name
    end
    

    routes.rb:

    resources :communities, :path => "shop", do
      resources :community_topics, :path => "topic"#, :as => :'topic' *
    end
    
    # * named route 'community_topic' can conflict with 'community_topics' of standalone route for CommunityTopic. Let it be by default: 'community_community_topic'.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Rails 3.2 and am attempting to make a scoped nested resource
Hi this is my first time using nested resources. I did rake routes and
I have a nested resource under my admin namespace: The admin/topic/comments_controller.rb is a resource
Possible Duplicate: Android - Open resource from @drawable String First of all sorry for
First of all: I'm using Microsoft Visual Studio 2012 I am a C#/Java developer
First of all, this isn't for a keylogger, it's for an input in a
first of all some details: I configured security as below in web.xml view plaincopy
First of all, I'm quite new to the Android and JAVA world (coming from
first of all i would like to say i know its probably an easy
First of all there is probably a question like this already but i couldn't

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.