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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:47:12+00:00 2026-05-16T00:47:12+00:00

I have a partial that contains a form: <% form_for :message, :url => {

  • 0

I have a partial that contains a form:

<% form_for :message, :url => { :action => "create" }, :html => { :id => 'form' } do |f| %>
  <%= f.error_messages %>

  <%= f.label :title, "title" %>
  <%= f.text_field :title %>

  <%= f.label :tag, "tag" %>
  <% if controller.controller_name == "tags" %>
    <%= f.text_field :tag_list, :value => @title %>
  <% else %>
    <%= f.text_field :tag_list %>
  <% end %>

  <%= f.label :name, "name" %>
  <%= f.text_field :name %>

  <%= f.label :email, "email" %>
  <%= f.text_field :email %>

  <%= f.label :title, "message" %>
  <%= f.text_area :content %>

  <%= f.submit 'submit' %>

<% end %>

I’m using this in two controllers: messages and tags. It works fine in the messages controller but not in the tags controller. When it’s rendered in tags#show it autofills the tag field. When a message is submitted from tags#show I’m redirected to the root of the website with a flash error “Tag does not exist.”

tags controller:

class TagsController < ApplicationController
  before_filter :redirect_if_doesnt_exist#, :only => :show

  def show
    @title = Tag.find(params[:id]).name
    @tag = Tag.find(params[:id])
    @entries = Entry.paginate(Entry.find_tagged_with(@tag), 
            :page => params[:page], :per_page => 10, :order => "name")
    @messages = Message.paginate(Message.find_tagged_with(@tag), 
            :page => params[:page], :per_page => 10, :order => "updated_at DESC")
    @related_entries = Entry.tagged_with(@tag, :on => :tags)
    @related_tags = @related_entries.collect{|x|x.tags}.flatten.uniq
    @related_tags.delete(@tag)
  end

  private
  # Redirect if requested tag does not exist
  def redirect_if_doesnt_exist
    @tag = Tag.find(params[:id]) rescue nil
    if @tag.nil? # maybe "or @tag.empty?" could solve the empty tag issue
      flash[:error] = 'Tag does not exist.'
      redirect_to '/'
    end
  end
end

In case it isn’t clear: The partial is shown in the view, the form within it just doesn’t submit the data from the tags controller and is redirected. The partial works fine from the messages controller. This is a Rails 2.3.x application.
Thank you for reading my question, your time is appreciated.

  • 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-16T00:47:13+00:00Added an answer on May 16, 2026 at 12:47 am

    Your problem is the URL of the form partial is only the action:

    <% form_for :message, :url => { :action => "create" }, :html => { :id => 'form' } do |f| %>
    

    If you include this in a view that isn’t under messages_controller, it’ll call the wrong action. If you include this ina a tags view, it’ll try to call the create action for tags_controller instead.

    It’ll probably work if you just add the controller too:

    <% form_for :message, :url => { :controller => :messages, :action => :create }, :html => { :id => 'form' } do |f| %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC Partial View that contains a Html.TextBox that is configured
I have a page which contains a html.RenderPartial, that renders an ASP.NET MVC partial
say, I have a partial class that contains a custom property like this public
if i have created a view model and have a partial form that is
I have an Ajax form in my Rails app that contains the Recaptcha markup
I have a quite average form in Rails, trough blog_kit <% form_for(@blog_post, :html =>
I have a donation form that contains an update panel that contains a dropdown
I have a number of pages that include the same partial view which contains
I have a partial that contains a header, a subheader and potentially one or
I have a partial that I want to display in a layout only when

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.