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>

有帮助吗?

解决方案 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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top