ruby on rails - Tweaking from :var to @var - makes problems and solves problems -


could on below issue. post content form not working. have laid out relevant code below.

tweaking @video_post :video_post, breaks form form works on homepage.

routing error  no route matches [post] "/users/1" 

using @video_post - form works on home-page website breaks elsewhere.

undefined method `model_name' nilclass:class 

can please me figure out?

many many thanks.

i have form in shared/form - _form.html.erb

  <%= form_for(@video_post) |f| %>     <%= f.text_field :video_title, placeholder: "video title"  %>     <%= f.text_area :video_description, placeholder: "description" %>     <%= f.text_field :video_url, placeholder: "url" %>     <%= f.submit "post", class: "submit" %>   <% end %> 

i render /users/_new.html.erb using:

<%= render :partial => 'shared/form', :video_posts => @video_posts %> 

which rendered application.html.erb using:

<%= render :partial => 'users/new', :locals => { :user => @user ||= user.new } %> 

video posts controller

class videopostscontroller < applicationcontroller    before_filter :signed_in_user     def create     @video_post = current_user.video_posts.build(params[:video_post])     if @video_post.save       flash[:success] = "video posted!"       redirect_to root_path     else       render 'static_pages/home'     end   end    def destroy    end   end 

static pages controller

class staticpagescontroller < applicationcontroller     def home     @video_post = current_user.video_posts.build if signed_in?   end   end 

videopost model

class videopost < activerecord::base   attr_accessible :video_category, :video_description, :video_title, :video_url   belongs_to :user    validates :user_id,           presence: true   validates :video_title,       presence: true   validates :video_description, presence: true, length: { maximum: 140 }   validates :video_url,         presence: true    default_scope order: 'video_posts.created_at desc'  end 

user model

class user < activerecord::base   attr_accessible :comment, :email, :password, :password_confirmation, :username   has_secure_password    has_many :video_posts, dependent: :destroy    before_save { |user| user.email = user.email.downcase }   before_save :create_remember_token      validates :username, presence: true, length: { maximum: 30 }   valid_email_regex = /\a[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i   validates :email, presence: true, format: { with: valid_email_regex },                      uniqueness: { case_sensitive: false }    validates :password, length: { minimum: 6 }   validates :password_confirmation, presence: true    private    def create_remember_token     self.remember_token = securerandom.urlsafe_base64   end end 

stack traces when using form_for - @video-post

app/views/shared/_video_post_form.html.erb:3:in `_app_views_shared__video_post_form_html_erb__4602377331012207168_70262656586760' app/views/users/_new.html.erb:3:in `_app_views_users__new_html_erb___487495860206913900_70262669645280' app/views/layouts/application.html.erb:25:in `_app_views_layouts_application_html_erb___3991259861222421382_70262670169940' 

when using :video_post

the form either doesn't work or gives me

routing error  no route matches [post] "/users/1" 

thanks!


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -