开发者

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

开发者 https://www.devze.com 2023-03-18 11:47 出处:网络
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\"]),

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 sim开发者_StackOverflow中文版ilar would be great.

Greetings

Sandro


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号