RoR - Scaffolding - unedfined method 'to_sym' for nil:NilClass only an error in the edit method
undefined method `to_sym' for nil:NilClass
I have this error only in my edit page of my nifty_scaffold.
This is _form.html.erb
<% form_for @progress do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :date %><br />
<%= f.date_select :date %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<p>
<%= f.label :weight %><br />
<%= f.text_field :weight %>
</p>
<p>
<%= f.label :fatpercentage %><br />
<%= f.text_field :fatpercentage %>
</p>
<p>
<%= f.label :height %><br />
<%= f.text_field :height %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>
This is edit.html.erb
<% title "Edit Progress" %>
<%= render :partial => 'form' %>
And this is my controller:
class ProgressesController < ApplicationController
def new
@progress = Progress.new
end
def create
@progress = Progress.new(params[:progress])
if @progress.save
flash[:notice] = "Successfully created progress."
redirect_to progresses_url
else
render :action => 'new'
end
end
def edit
@progress = Progress.find(params[:id])
end
def update
@开发者_如何学Goprogress = Progress.find(params[:id])
if @progress.update_attributes(params[:progress])
flash[:notice] = "Successfully updated progress."
redirect_to progresses_url
else
render :action => 'edit'
end
end
def index
@progresses = Progress.all
end
end
What could be wrong? I can't seem to find my error :-S. It seems that it: - fetches the data correctly - can't insert the db-values into the "edit view" fields.
I'm using :float, :string and :date as data types in the scaffold.
Just for the completed post, this is my error: NoMethodError in Progresses#edit
Showing app/views/progresses/edit.html.erb where line #3 raised:
undefined method `to_sym' for nil:NilClass
Extracted source (around line #3):
1: <% title "Edit Progress" %>
2:
3: <% form_for @progress do |f| %>
4: <%= f.error_messages %>
5: <p>
6: <%= f.label :date %><br />
At line 6 the log of the code ends...
Edit: It seems to be an error in my routes.rb. This is currently commented:
map.edit_progress "edit_progress", :controller => "progresses", :action => "edit"
when i uncomment it, it gives an error also in my index view.
For some reason, this is called: 'http://127.0.0.1:3001/progresses/1/edit', shouldn't it be: 'http://127.0.0.1:3001/progresses/edit/1' ? Even though it seem's that the "edit view" is called... Perhaps this is the reason why the values aren't filled in, in my view...
What could be my solution?
I will suggest two step debugging here:
Remove all your code from the edit view and a add some plain text in it, then access your page in the browser and see if you get any error or new error or no error
If you get any new error then it might help you in solving the issue or in your controller edit action raise the @progress to see whether it is being set
def edit @progress = Progress.find(params[:id]) raise @progress.inspect end
These two steps might help you in resolving the issue.
精彩评论