Sandro L
Sandro L

Reputation: 1160

How to get an argument for link_to dynamically from the site rails 3

I am using a the link_to method in Rails the unobstrusive jQuery way:

<%= link_to "save", 
            update_elements_diagram_path(diagram, :shown_elements => ["speed", "position_break"]),
            :method => :post, :remote => true, :class => "close",
            :onclick => "stringViewsTableLoading()" %>

This works. But now I want to get the arguments "shown_elements" dynamically from the users inputs. I know how to get them from the form to javascript, but how from javascript to Rails?

 ... shown_elements => "getShownElements()"

or something similar would be great.

Greetings

Sandro

Upvotes: 0

Views: 83

Answers (1)

Dominic Goulet
Dominic Goulet

Reputation: 8113

Not sure I see what you mean there, so I guess that you somehow have a few fields on your page, and that what you want is to get the value of those fields in the :shown_elements.

This is not how it's supposed to be done. Think the other way around. You are posting a form using :method => :post, which means that those will be accessible in your target controller using params[].

def DiagramsController < ApplicationController

    def update_elements
        shown_elements = params[:shown_elements] # or something like this.
    end

end

Hope this helps!

Upvotes: 1

Related Questions