views:

482

answers:

8

I'm doing a tutorial from Head-First Rails (via Safari Online) and cannot get edited HTML to show up in the browser (the changes, I mean). Specifically, I'm just changing the label for one of the columns from "Seat seq id" to "Seat #". I've opened the four view files, edit, index, new and show.html.erb. Everywhere there's an 'f.label :seat_id_seq' I've changed that to 'f.label "Seat #"'. For Table headers I've put Seat # inside the tags. I've saved the files and refreshed the browser (and even restarted the server), but all the views still have Seat id seq.

What am I missing? I've checked the errata but nothing relevant there.

Edit #7: Please note that it was due to an incompatibility between Rails 2.3.2 and the use of Vim patchmode and/or backup files, so none of the upvoted answers is correct. I'm putting this here so you can find the correct resolution without having to slog through all the posts.

Edit #1: Contents of routes.rb

ActionController::Routing::Routes.draw do |map|
  map.resources :tickets
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

Edit #2: I'm using gvim to edit, on Vista (no choice about that).

Edit #3: Does not appear to be starting in development mode. But shouldn't restarting the server get around that?

Edit #4: Mongrel output:

C:\Users\kathyj\Desktop\tickets>ruby script/server -e development
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server

Edit #5: Restarting the browser did not help.

Edit #6 @Sarah Mei:

<h1>New ticket</h1>

<% form_for(@ticket) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :seat_id_seq, "Seat #" %><br />
    <%= f.text_field :seat_id_seq %>
  </p>
  <p>
    <%= f.label :address %><br />
    <%= f.text_area :address %>
  </p>
  <p>
    <%= f.label :price_paid %><br />
    <%= f.text_field :price_paid %>
  </p>
  <p>
    <%= f.label :phone %><br />
    <%= f.text_field :phone %>
  </p>
  <p>
    <%= f.label :email_address %><br />
    <%= f.text_field :email_address %>
  </p>
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

<%= link_to 'Back', tickets_path %>

That field still says Seat id seq.

@ Mark Robinson: changing the New Ticket header was not picked up on browser refresh. Also I don't get all the Mongrel output you do, and I note I'm using a newer version of Rails.

N.b. My Rails experience should be measured in hours, not days.

@Ghoti: (1) Ctrl-F5 made no difference. I've also turned off cacheing, as vrish88 suggested. (2) I shoved your <%= nil.fail %> into app\views\tickets\new.html.erb right above the f.label for the name field, but it displayed the same as ever. I even tried using IE; everything works but none of the changes I've made shows up. (3) I found log\development.log, but I don't know what you're looking for. It's got a lot of Processing and Rendering lines, and shows some migrations. The migrations that added a column do not show up in the view. The migration that created another table, I can see its page.

A: 

The first place I would check is the routes.rb file.

Berek Bryan
A: 

Maybe those pages are cached by rails or your browser?

nan
The tutorial says to just refresh the browser and changes should appear. I've done that, but just in case Rails caches I restarted the server.
kajaco
+2  A: 

Make sure rails is in development mode. When you run script/server do you see the line below. Mongrel startup output below.

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.2.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.5 available at 0.0.0.0:3000
** Use CTRL-C to stop.
Mark Robinson
NO. But neither does 'ruby script/server -e development' produce that line. I'm using mongrel.
kajaco
It sounded like you were in production mode, but if you start the sever that way you should def be in dev mode. Have you tried just adding a simple header like <h1>hello</h1> to the .html.erb file to see if it shows up?
Mark Robinson
A: 

The label method takes an optional parameter specifying the text.

f.label :seat_id_seq

is implicitly expanded to

f.label :my_model, :seat_id_seq

iff it is enclosed by a form_for tag that specifies the model. So, all you need to do is add the text parameter to your call.

f.label :seat_id_seq, "Seat #"
# => <label for="seat_id_seq">Seat #</label>
Sarah Mei
Your assumption is incorrect, as least as far as this tutorial is concerned. The generated code is '<%= f.label :seat_id_seq %><br />' and the tutorial specifically says to change it to '<%= f.label "Seat #" %><br />'
kajaco
The may be wrong then because you need to specify which attribute you want to target with the label tag. You would want something like: <%= f.label :seat, "Seat #"%>
vrish88
If you check out the docs for the label method (linked in my answer) it takes an object, a method, and text - text defaults to the method name. The tutorial is wrong if it's only passing it one parameter.
Sarah Mei
If the tutorial is wrong, then why do all the "f.label :seat_id_seq" types of calls work? Everything is working, it's just that changes are not being picked up, including simple HTML changes in table headers, for example.
kajaco
I RTFM'd and updated my answer. If you have an enclosing form_for tag that specifies the model, you can leave the model parameter off your call, which is evidently what you're doing. So, all you need to do is add the extra param. Next time post the whole view. :)
Sarah Mei
+1  A: 

I would try restarting the browser. Unless you explicitly turned on caching in your Rails app then the server itself shouldn't be caching the content.

I had this problem with Firefox and I would have to restart the browser every once and a while to see the changes. However there is a way you can tell Firefox to stop caching content. Check out: Turn off caching

vrish88
A: 

I've never used the f.label style helpers, but what you're doing seems correct. You can go about it in a jankier fashion if you:

  1. Write out a label tag yourself, in HTML: <label for="seat_id_seq">Seat #:</label>
  2. Use label as follows: <%= label 'ticket', 'seat_id_seq', 'Seat #' %> See label and label_tag.

Be sure you're actually editing the views you need to. Maybe you have edit, show, etc. views in other directories also.

Sarah Vessels
+2  A: 

I think it's browser caching. Try pressing ctrl-F5 rather than just F5.

What's appearing in your log when the page is rendered?

If you want to make sure that a template is being re-loaded then put something error prone in it and see if you get the exception screen, something like <%= nil.fail %>. If it doesn't fail then it isn't being reloaded. It could be something to do with timestamps on your machine, development mode looks at the timestamps to see what needs to be reloaded.

The label command is correct. I recommend downloading Rails Brain and Ruby Brain so you have the documentation to hand and get straight to it. The documentation says

label(object_name, method, text = nil, options = {})

Because you're in a form helper (with the block parameter f) the object name parameter is assumed.

Ghoti
A: 

I downgraded the rails gem to 2.1.2 and my code works fine.

Edit: Apparently there was some change in the way Rails keeps track of which views files to show (see an explanation of sorts here). I only found that link after I did some trial-and-error testing and discovered that if I removed the backup and patchmode files that I have configured Vim to automatically make, and restarted the server, my changes were picked up while using v. 2.3.2.

I have changed my .vimrc so that those files are no longer made (.swp files don't cause a problem). It's only in the views dir that these other files were problematic. I specifically tested in the controllers dir and had no difficulty with the presence of a patch file. Now I can make views changes and a simple refresh (F5) picks them up immediately.

kajaco
Heh, glad you figured it out.
Sarah Mei