Note that there are some explanatory texts on larger screens.

plurals
  1. POObjects Being Attached to their Creator Question
    primarykey
    data
    text
    <p>I am working on a rails application where one user class named (submitters) are able to login and once they are logged in they create videos. My videos controller is here:</p> <pre><code>class VideosController &lt; ApplicationController def index @videos = Video.find :all end def new @submitter = current_submitter @video = @submitter.videos.build end def create @submitter = current_submitter @video = @submitter.videos.build(params[:video]) if @video.save @video.convert flash[:notice] = 'Video has been uploaded' redirect_to :action =&gt; 'index' else render :action =&gt; 'new' end end def show @video = Video.find(params[:id]) end def destroy @video = Video.find(params[:id]) @video.destroy flash[:notice] = "Successfully deleted the video." redirect_to root_url end def update_date @video = Video.find(params[:id]) @video.update_attributes(params[:video]) flash[:notice] = "Successfully added a launch date!" redirect_to @video end end </code></pre> <p>As you can probably see, I am trying to construct the controller so that when a video is created, it is created as belonging to the submitter who upload the video (via the video new view). I am using a auth system with a current_submitter method written in the application controller.</p> <p>Now it lets me upload a video fine when I am logged in as a submitter. The trouble for me is working out how to display information in my view. If I want to display some columns with information about the video and then others with information about the submitter who uploaded the video, how do I go about doing that from the controller (index action), into the index view. My current view which does not work in below:</p> <pre><code> &lt;% title "Films Submitted" %&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Film Type&lt;/th&gt; &lt;th&gt;Premiere&lt;/th&gt; &lt;th&gt;Company&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;/tr&gt; &lt;% for video in @videos do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= link_to video.title, video %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= video.film_type %&gt;&lt;/td&gt; &lt;% if video.premiere == "true" %&gt; &lt;td&gt;Premiere&lt;/td&gt; &lt;% else %&gt; &lt;td&gt;&lt;%= %&gt;&lt;/td&gt; &lt;% end %&gt; &lt;td&gt;&lt;%= video.submitter.company %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= video.submitter.name %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to "Delete", video, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; &lt;br&gt;&lt;br&gt; &lt;%= link_to "Upload a Video", new_video_path %&gt; </code></pre> <p>Any suggestions or tips from rails developers would be much appreciative... I am new and trying to learn.</p> <p>Video Model:</p> <pre><code>class Video &lt; ActiveRecord::Base belongs_to :submitter has_attachment :content_type =&gt; :video, :storage =&gt; :file_system, :max_size =&gt; 50.megabytes end </code></pre> <p>Submitter Model:</p> <pre><code>class Submitter &lt; ActiveRecord::Base acts_as_authentic has_many :videos end </code></pre> <p>Schema:</p> <pre><code> create_table "videos", :force =&gt; true do |t| t.string "title" t.text "description" t.string "state" t.datetime "created_at" t.datetime "updated_at" t.string "content_type" t.integer "size" t.string "filename" t.string "film_type" t.boolean "premiere", :default =&gt; false t.date "preferred_date" t.text "reason" t.integer "submitter_id" t.date "actual_date" end create_table "submitters", :force =&gt; true do |t| t.string "name" t.string "company" t.string "email" t.string "username" t.string "crypted_password" t.string "password_salt" t.string "persistence_token" t.datetime "created_at" t.datetime "updated_at" t.integer "video_id" end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload