Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Rails, how do you use RESTful controllers with Haml?

I'm getting started on figuring out how to use RESTful design. I have this action:

# GET /feedback_messages
# GET /feedback_messages.xml
def index
  page = params[:page]
  page ||= 1
  @feedback_messages = FeedbackMessage.paginate(
    :all,
    :page => page,
    :per_page => 20,
    :order => 'updated_at'
  )

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @feedback_messages }
  end
end

And I have the template...

views/feedback_message/index.haml

When I hit it with app.get '/feedback_messages' I get an error saying "Missing template feedback_messages/index.erb".

How do I tell Rails that I want it to use the Haml template?

like image 645
Ethan Avatar asked Dec 10 '22 22:12

Ethan


1 Answers

If you are running HAML - first make sure that you've installed HAML to the application... by running haml --rails . at the root of your project. Then from there make sure all of your HAML files are named [filename].html.haml - which breaks down to filename.format.interpreter. It's important you do this in REST specially because of the respond_to format block.

like image 108
Tim Knight Avatar answered Dec 12 '22 10:12

Tim Knight