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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:11:36+00:00 2026-06-16T02:11:36+00:00

The following works great for carrying forward data from one page to another: <%=

  • 0

The following works great for carrying forward data from one page to another:

<%= link_to 'New Work Order', new_workorder_path, :class => 'btn btn-primary', :onclick =>  session[:worequest_id]  %>

How would I add a 2nd field? The following doesn’t work:

          <%= link_to 'New Work Order', new_workorder_path, :class => 'btn btn-primary', :onclick =>  session[:worequest_id] = @worequest.id, [:client_id] = @worequest.client_id %>

Thanks!

UPDATED

This is the code I’m using in the new work order form. It picks up the worequest_id field from the session

       <% if session[:worequest_id] != nil %>
        <%= f.hidden_field :worequest_id, :value => session[:worequest_id] %>
  • 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-16T02:11:38+00:00Added an answer on June 16, 2026 at 2:11 am

    onclick doesn’t really work this way – it’s an html attribute used to store JavaScript code to be executed when the element is clicked. While you can use it to evaluate Ruby code in the context of a Ruby method call (in this case as part of the options hash given to link_to), it doesn’t really make sense to do so.

    In your first example, it doesn’t actually do anything. If you check your rendered html on the page where that link appears, I expect it evaluates to something like <a href="..." onclick="6">New Work Order</a>. You can, however, store data in session (which is persistent for as long as the user remains logged in), which is why you’re seeing this data carrying forward from page to page.

    If you’re trying to fill in default values for the new workorder, you could pass them as params to the path method:

    link_to 'New Work Order', 
      new_workorder_path('workorder[worequest_id]' => @worequest.id, 
                         'workorder[client_id]'    => @worequest.client_id),
      :class => 'btn btn-primary'
    

    In your workorders#new action, your model instantiation would need to include the params:

    def new
      @workorder = Workorder.new(params[:workorder])
    end
    

    However, this might not be the best way to proceed. If there will always be a client or worequest associated with a workorder, you might want to look into nested routes.

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

Sidebar

Related Questions

The following code snippet from my activity's onCreate() works great (i.e. cursor.moveToFirst() is true
I am using following JavaScript/Ajax to read page content, This script works great but
The following works great on my data in column 12 but I have over
The following works great (thanks to gracious assistance by this community!) Function RangeToArrayToRange(inputRange as
I am using the following which works great. I am just wondering if it
I have the following code that works great for row click, but I want
The following bit of code works great in everything but IE. In IE, the
I've implemented the following code on the site I'm working on which works great,
I have the following code running on my Android device. It works great and
I'm trying to execute the following line: exit | sqlplus username/password@sid @test.sql Works great

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.