Note that there are some explanatory texts on larger screens.

plurals
  1. POtrack model not being created in my rails app
    primarykey
    data
    text
    <p>in my rails app, I am running into an issue. As a heads up I am using devise.</p> <p>tracks_controller.rb</p> <pre><code>def new @track = Track.new end def create @track = current_user.tracks.build(params[:content]) if @track.save flash[:success] = "Track created!" redirect_to @user else render 'static_pages/home' end </code></pre> <p>users_controller.rb</p> <pre><code>def show @user = User.find(params[:id]) @tracks = @user.tracks if signed_in? @track = current_user.tracks.build end end </code></pre> <p>I am logged in as a current user, and when I try to add a new track (through the current user) it is not saving.. (and instead redirects to root_url)</p> <p>track.rb</p> <pre><code>class Track &lt; ActiveRecord::Base attr_accessible :content belongs_to :user end </code></pre> <p>user.rb</p> <pre><code>class User &lt; ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :username, :email, :password, :password_confirmation, :remember_me # attr_accessible :title, :body validates :username, uniqueness: { case_sensitive: false } has_many :tracks, dependent: :destroy end </code></pre> <p>shared/_track_form.html.erb</p> <pre><code>&lt;%= form_for(@track) do |f| %&gt; &lt;div class="track_field"&gt; &lt;%= f.text_area :content, placeholder: "Upload a youtube song URL...", :id =&gt; "message_area" %&gt; &lt;/div&gt; &lt;%= f.submit "Post", class: "btn btn-large btn-primary" %&gt; </code></pre> <p>relavent section for /users/show.html.erb</p> <pre><code>&lt;div class="span8"&gt; &lt;% if signed_in? %&gt; &lt;section&gt; &lt;%= render 'shared/track_form' %&gt; &lt;/section&gt; &lt;% end %&gt; </code></pre> <p>I believe the issue is in my TracksController #create method, however I just can't figure it out. any help is greatly appreciated, thanks!</p>
    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.
    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