Problem in Edit row in plugin

8 views
Skip to first unread message

Bahar

unread,
May 11, 2015, 3:07:30 AM5/11/15
to rubyonra...@googlegroups.com
Hi
I´m new in ruby on rails. I´ve written a plugin in redmine. And add this plugin to projects tab. I need to show something in that new tab, and edit the data.
But now, I have 2 problems:
1. In the new tab, when I click on the Edit link, the edit page open in the new page out of projects tab.
2. In the new page, data get from database correctly and show correctly, but when I want to update data, show the error: Page not found

here is my code:

/config/routes.rb :

    get 'accounts', :to => 'accounts#index'
    post 'post/:id/edit', :to => 'accounts#edit'
    post 'post/:id/update', :to => 'accounts#update'

/app/controller/accounts_controller.rb:

    class AccountsController < ApplicationController
        unloadable
       
        def index
            @project = Project.find(params[:project_id])
            @accounts = Account.find(:all)
        end
   
        def edit
            @account = Account.find(params[:id])
        end
   
        def update
            @account = Account.find(params[:id])
            if @account.update_attributes(params[:account])
               redirect_to :action => 'edit', :id => @account
            else
               redirect_to :action => 'edit', :id => @account
            end
        end
   
    end

/app/views/accounts/index.html.erb:

    <h2>AccounstController</h2>
    <% @accounst.each do |account| %>
    <table border=1px>
    <% if account.project.to_s == @project.to_s then %>
    <% @id = account.id %>
    <tr>
    <td display=inline-block>Project name</td>
    <td><%= account.project %></td>
    </tr>
    <tr>
    <td display=inline-block>Cost</td>
    <td><%= account.cost %></td>
    </tr>
    <tr>
    <td display=inline-block>Income</td>
    <td><%= account.income %></td>
    </tr>
    <tr>
    <td display=inline-block>Factor</td>
    <td><%= account.factor%></td>
    </tr>
    <% end %>
    </table>
    <% end %>
    <%= link_to "Edit", {:action => 'edit', :id => @id } %>


/app/views/accounts/edit.html.erb:

    <h1>Editing account </h1>
    <%= form_tag :action => 'update', :id => @account do %>
   
    <p><label for="account_cost">Cost</label>:
    <%= text_field 'account', 'cost' %></p>
   
    <p><label for="account_factor">Factor</label>:
    <%= text_field 'account', 'factor' %></p>
   
    <p><label for="account_income">Income</label>:
    <%= text_field 'account', 'income' %></p>
   
    <%= submit_tag "save changes" %>
    <% end %>
    <%= link_to 'Back', {:action => 'index'} %>


Can anyone help me please?

Reply all
Reply to author
Forward
0 new messages