Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a title to tweets in Michael Hartl's Rails Tutorial
    text
    copied!<p>I'm trying to add titles to tweets to get some practice in Rails. I keep getting this error on the page where tweets are composed:</p> <pre><code>undefined method `title' </code></pre> <p>It highlights line 4 of the <code>app/views/shared/_micropost_form.html.erb</code> file:</p> <pre><code>&lt;%= form_for(@micropost) do |f| %&gt; &lt;%= render 'shared/error_messages', object: f.object %&gt; &lt;div class="field"&gt; &lt;%= f.text_area :title, placholder: "Event name" %&gt; &lt;%= f.text_area :content, placeholder: "Compose new micropost..." %&gt; &lt;/div&gt; &lt;%= f.submit "Post", class: "btn btn-large btn-primary" %&gt; &lt;% end %&gt; </code></pre> <p>Here is my <code>microposts_controller.rb</code> file:</p> <pre><code>class MicropostsController &lt; ApplicationController before_action :signed_in_user, only: [:create, :destroy] before_action :correct_user, only: :destroy def create @micropost = current_user.microposts.build(micropost_params) if @micropost.save flash[:success] = "Micropost created!" redirect_to root_url else @feed_items = [] render 'static_pages/home' end end def destroy @micropost.destroy redirect_to root_url end private def micropost_params params.require(:micropost).permit(:content) end def correct_user @micropost = current_user.microposts.find_by(id: params[:id]) redirect_to root_url if @micropost.nil? end end </code></pre> <p>and my <code>[ts]_create_microposts.rb</code> file:</p> <pre><code>class CreateMicroposts &lt; ActiveRecord::Migration def change create_table :microposts do |t| t.string :content t.integer :user_id t.string :title t.timestamps end add_index :microposts, [:user_id, :created_at] end end </code></pre>
 

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