title: Rails: Why can't I save a new model Instance to the database?
body: <p>The #create action of my controller looks like the following. I have no idea, why ruby/rails doesn't take the argument assignments and thus the object I am saving has al &quot;nil&quot;-attributes</p>
  <pre><code>def create
    @new_page = Page.new 
    @new_page.slug = helpers.create_slug_from_title(params[:title])
  
    # Yes, I should also save the rest of params and make
    # params a strongparameter object
          
    # how to handle errors on create ?
    begin 
      @new_page.save
    rescue
    end
  
  end
  </code></pre>
  <p>I'd be thankful for any hint.</p>
  <p>Yours</p>
  <p>von Spotz</p>
  <p>PS: In the console things don't look different.</p>
  <pre><code>2.7.0 :038 &gt; pn = Page.new
  2.7.0 :039 &gt; pn.slug = &quot;index-page&quot;
  2.7.0 :040 &gt; pn.slug
   =&gt; &quot;index-page&quot; 
  2.7.0 :041 &gt; pn
   =&gt; #&lt;Page id: nil, text: nil, slug: nil, created_at: nil, updated_at: nil, title: nil, streams_id: nil&gt; 
  2.7.0 :042 &gt; pn.save
     (0.2ms)  begin transaction
    Page Create (0.6ms)  INSERT INTO &quot;pages&quot; (&quot;created_at&quot;, &quot;updated_at&quot;) VALUES (?, ?)  [[&quot;created_at&quot;, &quot;2021-05-07 17:01:15.111775&quot;], [&quot;updated_at&quot;, &quot;2021-05-07 17:01:15.111775&quot;]]
     (31.5ms)  commit transaction
   =&gt; true 
  2.7.0 :043 &gt; Page.all
  Page Load (0.2ms)  SELECT &quot;pages&quot;.* FROM &quot;pages&quot; LIMIT ?  [[&quot;LIMIT&quot;, 11]]
  =&gt; #&lt;ActiveRecord::Relation [#&lt;Page id: 1, text: nil, slug: nil, created_at: &quot;2021-05-07 15:40:59&quot;, updated_at: &quot;2021-05-07 15:40:59&quot;, title: nil, streams_id: nil&gt;, #&lt;Page id: 2, text: nil, slug: nil, created_at: &quot;2021-05-07 16:46:00&quot;, updated_at: &quot;2021-05-07 16:46:00&quot;, title: nil, streams_id: nil&gt;, #&lt;Page id: 3, text: nil, slug: nil, created_at: &quot;2021-05-07 17:01:15&quot;, updated_at: &quot;2021-05-07 17:01:15&quot;, title: nil, streams_id: nil&gt;]&gt; 
  2.7.0 :044 &gt; 
  </code></pre>
  <p>PPS: The new controller with the create action and page_params as kindly posted by max</p>
  <pre><code>class PagesController &lt; ApplicationController
      
      def home
    end
      
      def show
          @page = Page.where(slug: params[:slug])
      end
      
      def new
          @new_page = Page.new
      end
      
      def edit
          @page = Page.where(slug: params[:slug])
          # error if @page.nil?
      end
      
  # POST /pages
    def create
      @page = Page.new(page_params) do |page|
        # smelly - should be handled inside the model not by the controller
        page.slug = helpers.create_slug_from_title(page.title)
      end
          
      if @page.save
        redirect_to @page, status: :created
      else
        render :new, status: :unprocessable_entity
      end
    end
          
    private
  
    def page_params
      params.require(:page)
                      .permit(:slug, :title, :text)
    end
          
  end
  </code></pre>