views:

37

answers:

1

I've written a rails site in the latest version of rails, based on knowledge of rails from a couple of years ago, and I've hit a horrible snag.

I foolishly decided to ignore the new RESTful routing system and hope for the best.

So all of my views are plain .erb, NOT html.erb

my routes file looks like this

map.connect '/crm/:action/:id', :controller => "contacts", :format => 'html'

here is an example of a method:

def update_emails
  Com.update_emails
  respond_to do |format|
    format.html {redirect_to(:action => 'list')}
  end
end

when it redirects to the 'list' action, I get a plain text file that my browser tries to download, instead of the html version of the page that I want.

Is there a simple way for me to tell rails to only send html format files?

Thank you!

EDIT:

list action

def list
  if params[:search]
    @contacts = Contact.search(params)
  else
    @contacts = Contact.find(:all, :order => "updated_at desc")
  end
end

and the view is a plain .erb file (problem is the same when I make it a .html.erb file)

Also, the same thing happens when I redirect_to other actions

A: 

You should use respond_to.

def update_emails
  Com.update_emails
  redirect_to(:action => 'list')
end

and then in the 'list' action

def list
  #some code here
  respond_to |format| do
    format.html {render :list}
  end
end
adivasile
I've tried that (except 'redirect_to', not 'render'), and get the same issue.
rob
That's not the same thing.I've edit my response.see if this works.
adivasile
Close! Thank you! You put me on the right track. Couple of adjustments. redirect_to(:action => 'list', :format => 'html') and respond_to do |format| and format.html {render(:action => 'list')} And it works!!!
rob