Strange error at render partial

14 views
Skip to first unread message

Turcu Marius

unread,
Aug 7, 2014, 2:24:12 AM8/7/14
to rubyonra...@googlegroups.com
Hello! I have some problems

I have a pages controler and a view called add_lesson.In this view i use
a partial to another view of lesson controller.This is the partial
_show.html.erb

<%= form_for @lesson do %>
<%= label_tag(:lesson_name, "Lesson title") %></br>
<%= text_field_tag :lesson_name, nil, class: "form-control" %></br>
<%= label_tag(:lesson_icon, "Choise icon") %>
<%= select_tag "lesson_icon", options_for_select([ "ico03",
"ico04","ico05","ico06" ])%></br></br>

<%= label_tag(:Title, "Subtitle 1") %></br>
<%= text_field_tag :sublesson_title, nil, class: "form-control" %></br>
<%= label_tag(:title, "Content") %></br>
<%=text_area_tag 'content', nil, rows: 3, class: 'form-control'%></br>



<%= label_tag(:video, "Video link") %><br>
<%= text_field_tag :video_link, nil, class: "form-control" %></br>
<%= submit_tag("Submit", class: "btn btn-primary") %>


<% end %>

IN lesson controler i have
def index
end

def create
#render text: params.inspect
@lesson = Lesson.new(lesson_params)

if @lesson.save
redirect_to lessons_url
else
render 'new'
end
end
def new
@lesson=Lesson.new
@lesson.build_sublesson
end
def show
@lesson=Lesson.all
end

private

def lesson_params
params.require(:lesson).permit(:lesson_name, :lesson_icon)
end


When i submit the form i receive an error like this First argument in
form cannot contain nil or be empty. It is from @lesson in the form but
i don't know how to fix it. Please help

--
Posted via http://www.ruby-forum.com/.

vishal singh

unread,
Aug 7, 2014, 2:30:57 AM8/7/14
to rubyonra...@googlegroups.com
change ur form like this 

<%= form_for @lesson do |f| %>
<%=f.label :lesson_name, "Lesson title" %></br>
<%= f.text_field :lesson_name, class: "form-control" %></br>
<%= f.submit %>


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e4be687c09bf52509f00b9dd4bce5443%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Turcu Marius

unread,
Aug 7, 2014, 2:55:05 AM8/7/14
to rubyonra...@googlegroups.com
Thanks vishal! yes and what you sad was a problem but it crash before
do.
It's keep telling me First argument in form cannot contain nil or be
empty

Javix

unread,
Aug 7, 2014, 3:16:57 AM8/7/14
to rubyonra...@googlegroups.com
As @vishal told it, your form should be coded as follows:

<%= form_for(@lesson) do |f| %> 
     <%= f.label :lesson_name %><br>
    <%= f.text_field :lesson_name %>
<% end %>

Try it as it is and post the errors full stack trace to have more idea on what is going on there. It is really difficult to figure out without that.
Your model should be named as Lesson.
You should have routes defined for Lesson resource as well.


Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages