Forum: Ruby on Rails params on controller and view

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7595ff5e64d9a309c29932d106959973?d=identicon&s=25 Human Dunnil (Guest)
on 2006-01-30 22:59
(Received via mailing list)
Hi,
I have a link that says:
<%= link_to_remote("Data", :update => 'pie_graph_div', :url => {
:action => :show_pie_graph, :mode => 'nums' }) %>

which calls *show_pie_graph*:
Controller:
	def show_pie_graph
		render :layout => false
		@mode = params[:mode]
	end
View:
<img src="/surveys/make_pie_graph/<%=@mode%>" />

But @mode on view always is nil.
I can see the :mode from the view by calling params[:mode] but not
from the controller.

What's the problem? Did I misunderstand something?

Thanks in advance,
- H
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-01-30 23:18
(Received via mailing list)
Human Dunnil wrote:

> from the controller.
Set @mode before calling render.


--
We develop, watch us RoR, in numbers too big to ignore.
7595ff5e64d9a309c29932d106959973?d=identicon&s=25 Human Dunnil (Guest)
on 2006-01-30 23:27
(Received via mailing list)
Thanks
3f900b38ec3b2c45427c354722fa4ce3?d=identicon&s=25 Tom Fakes (tomfakes)
on 2006-01-31 02:19
(Received via mailing list)
You need to swap the lines in the controller.

	def show_pie_graph
		@mode = params[:mode]
		render :layout => false
	end

The 'render' method uses the current state of the controller at the time
it
is called to setup the view.  At that time, @mode is not yet set, so
that is
what the view sees.
This topic is locked and can not be replied to.