Ok so I have been playing with extjs and rails for about a week and I
feel I have made good progress. But I have gotten stuck. I have an
extjs form that has a button that submits data to my login method. I
want to have the controller update just a div in my page without
reloading or redirecting the page. This works great if I use just an
normal ruby on rails link_to. However, when I use a extjs button and
set the handler to call the controller the controller cannot render a
partial. It just hangs.
So here is my exmple. I have a very simple forum:
[CODE]  var simple = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless
overridden
        url:''save-form.php'',
        frame:true,
        title: ''Sign In'',
        bodyStyle:''padding:5px 5px 0'',
        width: 350,
        defaults: {width: 230},
        defaultType: ''textfield'',
        items: [{
                fieldLabel: ''Screen Name'',
                name: ''screen_name'',
                allowBlank:false
            },{
              fieldLabel: ''Password'',
              name: ''password''
            }
        ],
        buttons: [{
            text: ''Login'',
            type: ''submit'',
            handler: function(){
            simple.form.submit({url:
''/users/login?format_ext_json'',
waitMsg: ''Authenticating..''});}
        },{
            text: ''Cancel''
        }]
    });[/CODE]
Then I have a users controller and inside that controller I have a
method:
[CODE]
 def login
    logger.info("test")
    @title = "Log in to pinktomato"
      if request.get?
        @user = User.new(:remember_me => remember_me_string)
      elsif param_posted?(:screen_name)
        @user = User.new()
        @user.screen_name = params[:screen_name]
        @user.password = params[:password]
        user = User.find_by_screen_name_and_password
(@user.screen_name,@user.password)
        if user
          logger.info("found user")
          user.login!(session)
          @user.remember_me? ? user.remember!(cookies) : user.forget!
(cookies)
          flash[:notice] = "User #{user.screen_name} logged in!"
          render :text => "I HOPE THIS SHOWS"
        else
          # Don''t show the password in the view
          @user.clear_password!
          flash[:notice] = "Invalid screen name/password combination"
        end
      end
  end[/CODE]The "render :text" never renders.. It actually just hangs
on the authenticating when u click the login button. What I am
assuming is that possibly the controller has lost reference to the div
it should update. Is this possile. Since when I use a regular link_to
command in rails the login method works fine. Only when called from
the extjs form.
I have tried lost of stuff so far even
[CODE]   respond_to do |format|
          format.ext_json { render(:update) {|page| page.replace_html
"home" ,:partial=>"loggedIn") } }
          end[/CODE]
I hope my problem makes sense. I cannot find reference to this
anywhere. I downloaded the extjs scaffold and I took at look at the
generated code because it does create a create method for the
scaffold. However this pre generated scaffold just redirects the user.
I don''t want the page to referesh. Is this my only choice?
[CODE]  def create
    @site = Site.new(params[:site])
    respond_to do |format|
      if @site.save
        flash[:notice] = ''Site was successfully created.''
        format.ext_json { render(:update) {|page| page.redirect_to
sites_path } }
      else
        format.ext_json { render :json => @site.to_ext_json(:success
=> false) }
      end
    end
  end[/CODE]Please any help would be appreciated..
Vince
I am getting a little further if I use
          respond_to do |format|
            format.ext_json { render(:update) {|page|
page.replace_html "home", :partial => "loggedIn"} }
          end
The partial loads, however the waiting message from the forum never
goes away.
It just hangs..
On Sep 2, 1:30 pm, Vince
<vcord...-MuS7yT3y0+cmp8TqCH86vg@public.gmane.org>
wrote:> Ok so I have been playing with extjs and rails for about a week and I
> feel I have made good progress. But I have gotten stuck. I have an
> extjs form that has a button that submits data to my login method. I
> want to have the controller update just a div in my page without
> reloading or redirecting the page. This works great if I use just an
> normal ruby on rails link_to. However, when I use a extjs button and
> set the handler to call the controller the controller cannot render a
> partial. It just hangs.
>
> So here is my exmple. I have a very simple forum:
>
> [CODE]  var simple = new Ext.FormPanel({
>         labelWidth: 75, // label settings here cascade unless
> overridden
>         url:''save-form.php'',
>         frame:true,
>         title: ''Sign In'',
>         bodyStyle:''padding:5px 5px 0'',
>         width: 350,
>         defaults: {width: 230},
>         defaultType: ''textfield'',
>
>         items: [{
>                 fieldLabel: ''Screen Name'',
>                 name: ''screen_name'',
>                 allowBlank:false
>             },{
>               fieldLabel: ''Password'',
>               name: ''password''
>             }
>         ],
>
>         buttons: [{
>             text: ''Login'',
>             type: ''submit'',
>             handler: function(){
>             simple.form.submit({url:
''/users/login?format_ext_json'',
> waitMsg: ''Authenticating..''});}
>         },{
>             text: ''Cancel''
>
>         }]
>     });[/CODE]
>
> Then I have a users controller and inside that controller I have a
> method:
>
> [CODE]
>  def login
>     logger.info("test")
>     @title = "Log in to pinktomato"
>       if request.get?
>         @user = User.new(:remember_me => remember_me_string)
>       elsif param_posted?(:screen_name)
>         @user = User.new()
>         @user.screen_name = params[:screen_name]
>         @user.password = params[:password]
>         user = User.find_by_screen_name_and_password
> (@user.screen_name,@user.password)
>         if user
>           logger.info("found user")
>           user.login!(session)
>           @user.remember_me? ? user.remember!(cookies) : user.forget!
> (cookies)
>           flash[:notice] = "User #{user.screen_name} logged in!"
>           render :text => "I HOPE THIS SHOWS"
>
>         else
>           # Don''t show the password in the view
>           @user.clear_password!
>           flash[:notice] = "Invalid screen name/password
combination"
>         end
>       end
>   end[/CODE]The "render :text" never renders.. It actually just
hangs
> on the authenticating when u click the login button. What I am
> assuming is that possibly the controller has lost reference to the div
> it should update. Is this possile. Since when I use a regular link_to
> command in rails the login method works fine. Only when called from
> the extjs form.
>
> I have tried lost of stuff so far even
>
> [CODE]   respond_to do |format|
>           format.ext_json { render(:update) {|page| page.replace_html
> "home" ,:partial=>"loggedIn") } }
>
>           end[/CODE]
>
> I hope my problem makes sense. I cannot find reference to this
> anywhere. I downloaded the extjs scaffold and I took at look at the
> generated code because it does create a create method for the
> scaffold. However this pre generated scaffold just redirects the user.
> I don''t want the page to referesh. Is this my only choice?
>
> [CODE]  def create
>     @site = Site.new(params[:site])
>
>     respond_to do |format|
>       if @site.save
>         flash[:notice] = ''Site was successfully created.''
>         format.ext_json { render(:update) {|page| page.redirect_to
> sites_path } }
>       else
>         format.ext_json { render :json => @site.to_ext_json(:success
> => false) }
>       end
>     end
>   end[/CODE]Please any help would be appreciated..
>
> Vince