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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:09:10+00:00 2026-06-03T06:09:10+00:00

I have a 2 views that I want to use before the create action.

  • 0

I have a 2 views that I want to use before the create action.

1st view is add_sample_details.html.erb

<% form_tag add_expt_details_samples_path :method => :post do %>
    <% for sample in @samples %>
        <% fields_for "samples[]", sample do |form| %>
            <fieldset>
                <legend>Sample Name: <%= sample.name %></legend>
                <p><center><%= form.label :sample_title %>
                <%= form.text_field :sample_title, :size => 25 %></center></p>
                <table>
                    <tr>
                        <td>
                            <%= form.label :taxon_id %>
                            <%= form.text_field :taxon_id, :size => 15 %>
                        </td>
                        <td>
                            <%= form.label :scientific_name %>
                            <%= form.text_field :scientific_name, :size => 20 %>
                        </td>
                        <td>
                            <%= form.label :common_name %>
                            <%= form.text_field :common_name, :size => 15 %>
                        </td>
                    </tr>
                </table>
                <p>
                    <center>
                        <%= form.label :sample_descripition %><br \>
                        <%= form.text_area :description %>
                    </center>
                </p>
            </fieldset>
        <% end %>
    <% end %>
    <p><center><%= submit_tag "Next" %></center></p>

    <% for samp in @samples %>
        <%= hidden_field_tag("sample_ids[]", samp.id) %>
    <% end %>   
<% end %>

in the SamplesController, the add_expt_details looks like this

def add_expt_details
    # Collect the samples that were sent
    @expt_samples = Sample.find(params[:sample_ids])
  end

and the add_expt_details.html.erb looks like this

<% form_for @expt_samples, :url => create_study_samples_path, :html => { :method => :put }  do |f| %>
    <% @expt_samples.each do |samp|%>
        <% f.fields_for :expts do |form| %>
        <%= form.label :experiment_title  %>
        <%= form.text_field :expt_title, :size => 15 %><br \>
        <% end %>
    <% end %>
    <p><center><%= submit_tag "Next" %></center></p>
<% end %>

and my create_study action is like this

def create_study
     @study = Study.new(params[:study])
     # this method collects all the samples from the add_sra_details view from the hidden_field_tag   
     if current_user.id?
       # Put the current user_id in the study.user_id
        @study.user_id = current_user.id       
       if @study.save # Save the values for the study  
          # Update the Sample attributes 
          @samples = Sample.update(params[:samples].keys, params[:samples].values).reject { |p| p.errors.empty? }
           # For all those sample_ids selected by the user, put the study ids in the sample_study_id
           @samples.each do |samp|     
             @study.samples << samp        
           end       

           # get the ids_sent from the add_expt_details
            @expt_samples = Sample.find(params[:id])             

           # A Flash message stating the details would be prefereable..! (Means you have to do it)
           flash[:success] = "Your Study has been Created"           
           redirect_to add_expt_details_samples_path
       else
           flash[:error] = "Study Faulty" 
           render :action => "add_sra_details"
       end
     end
  end

The error message I get when I keep the @expt_samples = Sample.find(params[:id]) is “undefined method `keys’ for nil:NilClass”

and If I dont have the @expt_samples, it gives me an error “Couldn’t Find id in Sample”

Can some one suggest how can I update set of sample ids from one form and also create new Expt model records that are associated to the sample_ids in another form.

All suggestions are appreciated.

Cheers

  • 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-03T06:09:11+00:00Added an answer on June 3, 2026 at 6:09 am

    You need to refer to Rails’ accepts_nested_attributes_for

    To see how to link existing objects with forms, you can see examples here:

    http://josemota.net/2010/11/rails-3-has_many-through-checkboxes/

    rails 3 has_many :through Form with checkboxes

    has_many through checkboxes

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

Sidebar

Related Questions

I have a view in SQL Server 2008 that I want to use for
I have a view that I want to be converted into JSON. What is
I have an index view that I want to update automatically as the user
I have a partial view that I want to basically take care of itself
I have a MS SQL view that I want to make available as a
I have such view that handles user registration. After creating new user i want
My problem is that I want to have a tab bar view with its
I have a ImageView and draw some things on that view. Now I want
On each cell of my table view I want to have a bar that
I have a simple create action that save a product to DB. after saving

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.