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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:10:15+00:00 2026-06-12T01:10:15+00:00

I have a question about Rails. I have a table in my database without

  • 0

I have a question about Rails. I have a table in my database without primary key with these columns – person_id, year, salary. My problem is when I want to edit one of the salary. I can’t understand how to do it. That’s my code:

Salaries controller:

def index
    @salaries = Salary.all
end

def edit
    @salary = Salary.find_by_person_id_and_year(params[:person_id], params[:year])
    @people = Person.all
end

index.html.erb

<% @salaries.each do |salary| %>
    <b><%= salary.person.Name %></b>
    <b><%= salary.Year %></b>
    <b><%= salary.Amount %></b>
    <%= link_to "Edit", edit_salary_path(salary.person_id, salary.year)%>
<% end %>

So, I add this to my routes.rb:

get 'salaries/index', :to => 'salaries#index',:as => 'salaries'
get 'salaries/:person_id/:year', :to => 'salaries#show', :as => 'salary'   
get 'salaries/new/:person_id/:year', :to => 'salaries#edit', :as => 'new_salary'
get 'salaries/edit/:person_id/:year', :to => 'salaries#edit', :as => 'edit_salary'
put 'salaries/:person_id/:year', :to => 'salaries#update'
post 'salaries/:person_id/:year', :to => 'salaries#create'
delete 'salaries/:person_id/:year', :to => 'salaries#destroy'

but I have these error message in my _form.html.erb: “undefined method `join’ for nil:NilClass” on this line: <%= form_for(@salary) do |f| %>

def edit
    @person_id = params[:person_id]
    @year = params[:year]
    @salary = Salary.find_by_person_id_and_year(params[:person_id], params[:year])
    @people = People.all
end

def update
    @people = People.all
    @salary = Salary.new(params[:salary])
    if @salary.save
        flash[:success] = "Successfully edited salary"
        redirect_to salaries_path
    else
        @title = "Edit salary"
        render 'edit'
    end
end

_form.html.erb

<%= form_for(@salary, :url => salaries_path(:person_id => @person_id, :year => @year)) do |f|   %>
  • 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-12T01:10:16+00:00Added an answer on June 12, 2026 at 1:10 am

    Rails routing will automatically be looking for the id, so you will need to customise your routes.

    For example, instead of resources :salaries in config/routes.rb try something like:

    get 'salaries/index', :to => 'salaries#index',:as => 'salaries'
    get 'salaries/edit/:person_id/:year', :to => 'salaries#edit', :as => 'edit_salaries'
    put 'salaries/:person_id/:year', :to => 'salaries#update'
    

    With other routes as you need such as:

    get 'salaries/index', :to => 'salaries#index',:as => 'salaries'
    get 'salaries/:person_id/:year', :to => 'salaries#show', :as => 'salary'
    get 'salaries/new/:person_id/:year', :to => 'salaries#edit', :as => 'new_salary'
    get 'salaries/edit/:person_id/:year', :to => 'salaries#edit', :as => 'edit_salary'
    put 'salaries/:person_id/:year', :to => 'salaries#update'
    post 'salaries/:person_id/:year', :to => 'salaries#create'
    delete 'salaries/:person_id/:year', :to => 'salaries#destroy'
    

    And the form:

    form_for(@salary, :url => salary_path(:person_id => X, :year => Y)) do |f|
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about Rails database. Should I add index to all the
I have a question about ruby on rails and the process of assigning variables
Hi I have a question about ruby on rails Apparently I have a statement
Im new to rails and have a question about accessing relations of relations in
I have a general question about rails controllers/models: I have a model Providers, that
I have a very n00b question about Rails. What are the variables and methods
I'm new to Rails development and I have a question about handling an unknown
I have a rails application linked to a database table, which contains e-mail addresses
I have a fairly generic question about how to create a shortlist in rails.
I have a question about rails and how its relationships query builder, specifically how

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.