I’m new to RoR (came over from PHP). I am working on the backend of my
project now, and I’m basically trying to output a form that lets me
create a new ‘design’.
This is what I have in my routes.rb:
map.with_options(:namespace => “admin”) do |admin|
admin.resources :designs
end
In my design controller:
def new @design = Design.new
end
In my view for the form:
<% form_for([:admin, @design]) do |f| %>
<% end %>
When I attempt to view the form page, I get this error:
undefined method `admin_designs_path’ for #<ActionView::Base:
0x589b760>
I’ve been following the official guides to a T, so I’m not really sure
where I’ve gone wrong. Anyone able to shed some light about this? Many
thanks.
Thanks Sijo for the help. I’ve made the changes according to your
suggestions. The error message is now different, but I guess there’s
some improvement!
“undefined method `^’ for “f”:String”
My routes.db:
map.namespace(:admin) do |admin|
admin.resources :designs
end
My bad… I regenerated the controllers and models and the previous
error seemed to be gone but now I’m getting this error instead:
Called id for nil, which would mistakenly be 4 – if you really wanted
the id of nil, use object_id
If I understand correctly, this statement "<% form_for([:admin, @design]) do |f| %> " is trying to call the @design model with a nil
id, which results in this error. That seems inevitable as I’m trying
to create a new design through this form.
Thanks Coiln. I deleted that message actually because it slipped my
mind that the line which I defined @design as a Design model got
deleted off when I regenerated the controllers and models. I fixed
that already so now I’m stuck with another different undefined method
error:
undefined method `^’ for “f”:String
Where does this ^ come from? I’ve tried searching through Google and
other ruby forums but seems like I’m the only one having so much
trouble. I guess it might be just something obvious that I just can’t
get for some reason…!
trouble. I guess it might be just something obvious that I just can’t
get for some reason…!
I think a lot of people have had this problem, I believe it is a known
bug in Rails 2.3.4. I understand the easiest solution is to go down
to 2.3.3 if possible.
to create a new design through this form.
If the error occurred on that line then it suggests @design is nil
(@design is not a model it is a variable). You should set this up in
your ‘new’ action before displaying the view. Something like @design
= Design.new.
If this does not make sense then, if you have not done so already,
have a look at the rails guide Getting Started. See
<% form_tag do(:method => “get”) %>
Doing this is fine…
<% form_tag do %>
But this gives me the Undefined Method ‘^’ error once more.
Not sure why, but the only difference is that one is a get request,
the other is a post. Surely this can’t be broken as well? Seems like
it may be one of the most basic functions in Rails, and if it were to
be broken, too many people would have been affected by it already.
I think it is only an issue with Ruby 1.9 (with rails 2.3.4), but this
is only from memory, think a bit more googling (or searching the
archives of this list) would be needed to confirm this.
I think a lot of people have had this problem, I believe it is a known
bug in Rails 2.3.4. I understand the easiest solution is to go down
to 2.3.3 if possible.
Colin
What about generating normal forms? I can’t seem to do it without
errors.
<% form_tag do(:method => “get”) %>
Doing this is fine…
<% form_tag do %>
But this gives me the Undefined Method ‘^’ error once more.
Not sure why, but the only difference is that one is a get request,
the other is a post. Surely this can’t be broken as well? Seems like
it may be one of the most basic functions in Rails, and if it were to
be broken, too many people would have been affected by it already.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.