Search code examples
ruby-on-railsobjectcreation

rails cant create an object


So I am making a colors palette manager and both tables requested on the form are nested and properly related(I would like to also point out that I am a rookie to rails)

This whole code was working perfectly fine when in line 4 was requesting links instead of just the names and suddenly wont work anymore, thank you for the help in advance

<div class='nav_bar'>#</div>
    <% if @projects %>
        <% @projects.each do |project| %>
            <li><div class='container'><h1><%= project.name project_path(:id => project.id) %></h1>
                <ul>
                    <%= form_for project do %>
                    <%= fields_for :palette, project.palette do |palette| %>

                      <%= palette.label 'background_dark_color' %>:
                      <%= palette.text_field :background_dark_color, placeholder: '@palette.background_dark_color' %><br/>

                      <%= palette.label 'background_light_color' %>:
                      <%= palette.text_field :background_light_color, placeholder: "@palette.background_light_color" %><br/>

                      <%= palette.label 'dark_color1' %>:
                      <%= palette.text_field :dark_color1, placeholder: "@palette.dark_color1" %><br/>

                      <%= palette.label 'dark_color2' %>:
                      <%= palette.text_field :dark_color2, placeholder: "@palette.dark_color2" %><br/>

                      <%= palette.label 'light_color1' %>:
                      <%= palette.text_field :light_color1, placeholder: "@palette.light_color1" %><br/>

                      <%= palette.label 'light_color2' %>:
                      <%= palette.text_field :light_color2, placeholder: "@palette.light_color2" %><br/>

                      <%= palette.submit %>

                      <%= link_to 'Destroy',  project,  method: :delete, data: { confirm: 'Are you sure?' } %>

                    <% end %>
                    </div>
                </ul>

            <% end %></li>
        <%end%>
    <%end%>
    <div class='circle'><%= link_to "+", new_project_path %></div>
    <button type="button"><%= link_to "+", new_project_path %></button>

Solution

  • I think you are referring to the following line,

    <%= project.name project_path(:id => project.id) %>
    

    There is a mistake in this code. There are two ways to fix this.

    Solution 1

    If you want to display a link or an anchor tag this use replace this with the following code,

    <%= link_to project.name, project_path(:id => project.id) %>
    

    Solution 2

    If you don't want a link but, just the name to appear then, do the following,

    <%= project.name %>