On Thursday, August 7, 2014 8:24:12 AM UTC+2, Ruby-Forum.com User wrote:
>
> 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 
>
> -- 


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/. 
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ab580432-4b64-4d3d-90ac-5e8135b6afc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to