On Wednesday, May 21, 2014 7:42:39 AM UTC-4, Ruby-Forum.com User wrote:
>
> Hi everybody, in my view (operation_en_cours) I display the content of a 
> variable (myvariable) and I have a button linked to a method ( for 
> exemple change)defined in my controller in which I change the content of 
> my varible like this: 
> @myvariable="hello" 
> def change 
>     @myvariable="test" 
>         respond_to do |format| 
>         format.html { redirect_to pages_operation_en_cours_url } 
>         format.json { head :no_content } 
> end 
>
> But when I click on the button my fonction is called y saw it in the url 
> (http://192.168.152.196:3000/pages/change) but then in the view I always 
> have "hello". I think the is not refresh but I don't no how can I do? 
>
> Indeed if I define myvarible like this @myvariable=Article.all and then 
> def change 
>     @myvariable[0].name="test" 
>     @myvariable[0].save 
>         respond_to do |format| 
>         format.html { redirect_to pages_operation_en_cours_url } 
>         format.json { head :no_content } 
> end 
>
> and in my view @myvarible[0].name then when I call the method the view 
> is refresh and the name is change. 
>
> How can I do the "equivalent" of save for my variable? 
>
> Fab 
>
> -- 
> Posted via http://www.ruby-forum.com/. 
>

The problem is the redirect.  When you do a redirect, Rails actually 
responds with a code 301 to the browser and redirects the browser to the 
new url.  When Rails receives the redirected request, it's treated as a 
completely new request, so no instance variables will persist.

The only way to do what you want is to use a render instead of a redirect.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/a3f49d55-20c2-44b9-a35b-193d46150bd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to