Create button didn't changed and about 'root_path'


#1

I made Threadly site but i can see the difference. the sample(https://threadly-rails.herokuapp.com/)'s button "Create" is much fancy(green button) and mine is just a basic form button.
how can i change it?

another question
i don't know how to use 'root_path'
is redirect_to 'root_path' works? instead of redirect_to '/posts' ?

my view:

    <div class="header">
      <div class="container">
        <h1>threadly</h1>
      </div>
    </div>

    <div class="main">
      <div class="container">
        
        <!-- Form goes here -->

          <div class="container">
            <%= form_for(@new_post) do |f|%>
            	<div class="field">
                <%= f.text_field :comment ,  placeholder: "share your thought" %>
            	</div>
            	<div class ="actions">
                <%= f.submit "Create"%>
              </div>
           <%end%>
          </div>

	<ul class="comments">
  		<% @all_posts.each do |p| %>
  		<li><%= p.comment %></li>
  		<% end %>
	</ul>
        
        <ul class="comments">
          <li>Have you felt it?</li>
          <li>There has been an awakening.</li>
        </ul>

      </div>
    </div>

my controller:

class PostsController < ApplicationController
	def index
  	@new_post = Post.new
  	@all_posts = Post.order(created_at: :desc).all
	end
	
  
  def create
    @post=Post.new(post_params)
    if @post.save
      redirect_to '/posts'
    else
      render 'new'
    end
  end
 
   private 
  	def post_params
		params.require(:post).permit(:comment)
  	end
  
end

my routes:

Rails.application.routes.draw do
 
  
  root 'posts#index'
  get 'posts/create' => 'posts#create'
   resources :posts
end

#2

Hi @jusugang,

the sample's button "Create" is much fancy(green button) and mine is just a basic form button.
how can i change it?

That'll take some CSS. Probably something like:

button {
  background: transparent;
  color: green;
  border: none;
  cursor: pointer;
}

Your browser's developer tools will help you view the code for their button. You can usually pull them up by pressing F12 or Ctrl+Shift+I :slight_smile:

is redirect_to 'root_path' works?

Have you tried it? It should.


#3

thanks! i think i can fix it!:heart_eyes:


#4

This topic is solved.