Question

This is my controller for the app.

private
def app_params
    params.require(:login).permit(:name, :surname, :username, :password, :email)
end
def new 
    @login = Login.new app_params
    unless app_params.nil?
        @login.save

    end
end
def show 
    @post = Post.find(params[:id])
end
def create
    @login = Login.new(params[:login])
    if @login.save
        flash[:success] = "Saved"
        redirect_to root_path
    else
        render "new"
    end
end

Code for the new_login_path is:

<%= form_for Login.new do |f| %> so on..

The error message it shows is:

undefined method `logins_path' for #<#:0x007fba3824be28>

Was it helpful?

Solution 2

You need to define the action above private. every method you define below private is treated as private method. while the controller actions need to be publicly accessible. So Define the action above the private keyword.

def new 
  @login = Login.new app_params
  unless app_params.nil?
    @login.save
  end
end
def show 
  @post = Post.find(params[:id])
end
def create
  @login = Login.new(params[:login])
  if @login.save
    flash[:success] = "Saved"
    redirect_to root_path
  else
    render "new"
  end
end

private
def app_params
  params.require(:login).permit(:name, :surname, :username, :password, :email)
end

OTHER TIPS

The logins_path method should be generated automatically by Rails based on the contents of your config/routes.rb file. Do you have a line like this?

resources :logins

After you fix your routing issue, you'll want to move your action methods above the private declaration as in Manoj Monga's answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top