Reputation: 997
I have this controller method:
def slide_change
j=params[:val]
g=TargetPortfolio.new
@h,@lock=g.finding_the_concerned_id(j)
#@h , @lock both are array.
last=TargetPortfolio.last # TargetPortfolio is model class
last.update_attributes(folders: @h)
redirect_to :action => "target_port" #with this i need to pass @lock as argument
end
The other method target_port of controller:
def target_port
@h=TargetPortfolio.last.folders
# @lock from the slide_change
end
Available routes
slide_change GET /slide_change(.:format) Portfolio#slide_change
/:controller(/:action(/:id))(.:format) :controller#:action
I have target_port.erb which uses @h and @lock .Any guesses how i can do that.
Upvotes: 2
Views: 1459
Reputation: 2070
Change your redirect to
redirect_to :action => "target_port", :lock => @lock
and load it in the target_port
method with @lock = params[:lock]
Upvotes: 1
Reputation: 11017
You'd have to define the value that g
is giving in your routes.rb file for the target_port
action. so let's say g
is an ID number.
in routes.rb:
match '/TARGET/:id', :to => 'controller#target_port', :as => :target_port
so in your controller you can write:
def slide_change
j=params[:val]
g=some_function(j)
redirect_to target_port_path(g)
end
(more detailed)
In the new
view file, add this line
<%= hidden_field_tag "lock", @lock %>
the hidden field tag makes a param named "lock" that gets passed when the form is submitted, which you can access by putting this the create
action of your controller:
def create
...
@lock = params[:lock]
...
end
Upvotes: 2
Reputation: 10111
when i do this in my controller it looks like
redirect_to some_path(:params1 => params1_value, :params2 => params2_value)
Upvotes: 0