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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:50:09+00:00 2026-06-14T11:50:09+00:00

There must be an easy answer to this question, but I’m still unable to

  • 0

There must be an easy answer to this question, but I’m still unable to get it working.

I have a Ruby On Rails app that allows the user to manage projects with a database (create, update, show, edit, destroy, …, etc.). For example, when the user edits a projects, she/he is taken to a page, like http://:3000/projects/3/edit where she/he can modify entries the the form there. Notice the user is editing project 3 in this example.

To edit a project, the user click this button

<td><%= button_to 'Edit', { :action => "edit", :id => project }, :method => :get %></td>

which call this method

# GET /projects/1/edit
def edit
  @project = Project.find(params[:id])
end

and that works fine.

However, I added another method call updateFields, so that when a field is modified, a javascript function called updateFields is run and calls an AJAX request that modifies other related fields in the form. The following is an excerpt from updateFields:

<script language="JavaScript" type="text/javascript">
function updateFields(){
    $.ajax({
        url: "<%= update_fields_projects_url %>",
        data: {
            project_year: $('.project_year_class').val(),
            project_type: $('.project_type_class').val(),

            <snip>

        }
    });
}
</script>

In the controller, I can then get all the info I need in params array, like the following:

# PUT /projects/1
# PUT /projects/1.json

def update_fields

  @project = Project.find(params[:project])
  @project_year = params[:project_year]
  @project_type = params[:project_type]

  <snip>

  respond_to do |format|
    if @project.update_attributes(params[:project])
      format.js
      format.html
    else
      format.html { render :action => "update" }
      format.json { render :json => @project.errors, :status => :unprocessable_entity }
    end
  end
end

The problem I have is that I’m not able to update the form, and on the server, I see the following error messages

ActiveRecord::RecordNotFound (Couldn't find Project without an ID):
app/controllers/projects_controller.rb:101:in `update_fields'

Rendered /var/lib/gems/1.8/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.5ms)
Rendered /var/lib/gems/1.8/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.2ms)
Rendered /var/lib/gems/1.8/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (10.8ms)

If I specify the project id directly, all works fine

@project = Project.find(3)

My question is how do I get that id passed in params to the controller by the javascript function in the same way than project_year and project_type? in this example, it is 3, but it will be different for every project because it is assigned when the project is created.

Update1

<%= form_for(@project, :html => {:name => "ProjectInfo"}) do |f| %>

  <input type=button id=project_info_button_id value="Show Details" onclick="showHideDiv('project_info_id','project_info_button_id');">

  <div class="form input", id='project_info_id', style='display:none'>
    <% concat "Project Year" %>
    <%= f.text_field :ProjectYear, {:class=>"project_year_class", :Size=>6, :style=>"text-align:right"} %>

    <snip>

  <% 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-14T11:50:10+00:00Added an answer on June 14, 2026 at 11:50 am

    You need to pass the project id in the data section of the ajax request:

    <script language="JavaScript" type="text/javascript">
    function updateFields(){
        $.ajax({
            url: "<%= update_fields_projects_url %>",
            data: {
                project_year: $('.project_year_class').val(),
                project_type: $('.project_type_class').val(),
                id: <%= @project.id %>,
                <snip>
    
            }
        });
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there must be a really simple answer to this question, but I
I'm sure there must be an easy answer to this but everything I've googled
I feel like this must be very easy, but I can't find the answer
This is probably an easy question but I can't figure out the best answer
There must be an easy answer to this one.... I am trying to integrate
There must be a simple solution to this problem but for the love of
It feels like there must be some semi-simple solution to this, but I just
I am sure there must be a relatively straightforward way to do this, but
There is probably an easy answer for this, just not sure how to tease
I think I must be missing something obvious, but I'm unable to find this

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.