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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:14:33+00:00 2026-05-25T11:14:33+00:00

I am learning Rails by making a simple recipe tracking program. Here’s where I’m

  • 0

I am learning Rails by making a simple recipe tracking program. Here’s where I’m stuck: when I am on the form to create a new recipe in the system, if that recipe’s source (ie a book, magazine, etc) doesn’t currently exist I would like to create that too at the same time. In other words when I am looking at ‘recipe/new.html’, if I need to add a new source, using jQuery dialog (or another approach if that makes more sense) I would like to render ‘source/_form.html.erb’ (the partial for a new recipe source), create a new recipe source, and then inject that new record at the end of my select box.

From recipe/new.html:

<div class="field">
    <%= f.label :source %><br />
    <%= select("recipe", "source_id", Source.all.sort_by(&:title).collect {|s| [ s.title, s.id ] }, { :include_blank => true }) %>
    <%= link_to "new source", new_source_path (@source, :format => :js), :remote => true %>
</div>

From sources/new.js.erb

$("<%= escape_javascript render(:partial => 'sources/form') %>").dialog();
$('#new_comment_link').hide();

From controllers/sources_controller.rb

  # GET /sources/new
  # GET /sources/new.xml
  def new
    @source = Source.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @source }
      format.js
    end
  end

  # GET /sources/1/edit
  def edit
    @source = Source.find(params[:id])
  end

  # POST /sources
  # POST /sources.xml
  def create
    @source = Source.new(params[:source])

    respond_to do |format|
      if @source.save
        format.html { redirect_to(@source, :notice => 'Source was successfully created.') }
        format.xml  { render :xml => @source, :status => :created, :location => @source }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @source.errors, :status => :unprocessable_entity }
      end
    end
  end

The sources/form partial, which should render in jquery dialog then disappear on submit. When dialogue closes I want the new record created by this form to appended to the end of my select box on recipe/new.html:

<%= form_for(@source) do |f| %>
  <% if @source.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@source.errors.count, "error") %> prohibited this source from being saved:</h2>

      <ul>
      <% @source.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :author_last %><br />
    <%= f.text_field :author_last %>
  </div>
  <div class="field">
    <%= f.label :author_first %><br />
    <%= f.text_field :author_first %>
  </div>
  <div class="field">
    <%= f.label :media_type %><br />
    <%= f.text_field :media_type %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Thank you for taking the time to read through this.

EDIT: To be more explicit about what my problem is, the code above renders a dialog and allows me to submit a new source. However, after submission it redirects to the new source’s view page, rather than the new recipe form I started on before I opened the dialog.

  • 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-25T11:14:33+00:00Added an answer on May 25, 2026 at 11:14 am

    So, after all that, I just needed to change one thing in my partial. The change was from:

    <%= form_for(@source) do |f| %>
    

    to

    <%= form_for (@source, :remote => true) do |f| %>
    

    So at least I am now submitting records to the database. Unfortunately, now I can’t get the dialog to close after submit. I’ll do more research about that and ask another question if necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently learning rails by creating a simple project management app. I've gotten to
Learning rails and something smells a little funny. I have the following form for
I'm learning Rails by writing simple TODO tasks aplication. Two models are: class List
Hello I am new to Rails. I am learning rails 2.3.5 and checked Rails
I'm learning Rails, and got into a little problem. I'm writing dead simple app
I've created a simple application to assist me in learning Rails. Because I like
--still learning rails here.. I want to write a conditional statement such as: if
That title probably doesn't sound right, but forgive me, I'm learning Rails for the
Currently following the Learning Rails Screencasts at http://www.buildingwebapps.com/learningrails , making any necessary changes to
I am learning Rails and I have noticed that Rails continously uses helper method

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.