How to implement an edit action in a controller?

Hi…
I’m trying to edit a field in a table named software_cis. The name of
the controller is ci_controller and the action is give_functional_spec.
In give_functional_spec.rhtml file I wrote the code for interface. Then
in the ci_controller, I wrote:

def give_functional_spec
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

But this generated an error message: "The error occurred while
evaluating nil.functional_spec= "

Can anyone help to fix this issue please.

Regards

Suneeta Km wrote:

Hi…
I’m trying to edit a field in a table named software_cis. The name of
the controller is ci_controller and the action is give_functional_spec.
In give_functional_spec.rhtml file I wrote the code for interface. Then
in the ci_controller, I wrote:

def give_functional_spec
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

But this generated an error message: "The error occurred while
evaluating nil.functional_spec= "

Can anyone help to fix this issue please.

Regards

Now i made a modification in ci_controller:
def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

— !map:HashWithIndifferentAccess functional_spec: along with the data
entered is saved to the table.

How can i solve this?

Now i made a modification in ci_controller:
def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

— !map:HashWithIndifferentAccess functional_spec: along with the data
entered is saved to the table.

How can i solve this?

It will be helpful if you give the data type of the functional_spec.
Also the view file code for the ci form.

Now i made a modification in ci_controller:
def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

Try giving like this…

def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci][:functional_spec] # Changed
@software_ci.save
end

  • Karthik

Karthi kn wrote:

Now i made a modification in ci_controller:
def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

— !map:HashWithIndifferentAccess functional_spec: along with the data
entered is saved to the table.

How can i solve this?

It will be helpful if you give the data type of the functional_spec.
Also the view file code for the ci form.

The data type of functional_spec is text.

The code of give_functional_spec.rhtml is:

<%= render :partial=>‘cipart/ci_header’ %>

<%= start_form_tag ({:action => ‘give_functional_spec’, :method =>
‘post’}, :class => ‘itilform’)%>

Functional Specification
<%= text_area "ci", "functional_spec", "cols" => 80, "rows" => 5 %>
<%=submit_tag('Save') %>
<%= end_form_tag %>

Karthi kn wrote:

Now i made a modification in ci_controller:
def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

Try giving like this…

def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci][:functional_spec] # Changed
@software_ci.save
end

  • Karthik

I tried that also. But an occurred:
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]

Suneeta Km wrote:

Karthi kn wrote:

Now i made a modification in ci_controller:
def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end

Try giving like this…

def give_functional_spec
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci][:functional_spec] # Changed
@software_ci.save
end

  • Karthik

The problem while doing this is that while executing this method, it
tries to retrieve the data in params[:ci][:functional_spec]. But there
is no data in the hash, because the method in the controller is executed
first and only after that the view is executing.

The problem while doing this is that while executing this method, it
tries to retrieve the data in params[:ci][:functional_spec]. But there
is no data in the hash, because the method in the controller is executed
first and only after that the view is executing.

Correct. I think, you will have to change the approach.

So, for the first time when you render ‘give_functional_spec.rhtml’, try
to render without calling the method.

In controller where you call the ‘give_functional_spec’ method,

render :action => ‘give_functional_spec’

Try this.

Karthi kn wrote:

The problem while doing this is that while executing this method, it
tries to retrieve the data in params[:ci][:functional_spec]. But there
is no data in the hash, because the method in the controller is executed
first and only after that the view is executing.

Correct. I think, you will have to change the approach.

So, for the first time when you render ‘give_functional_spec.rhtml’, try
to render without calling the method.

In controller where you call the ‘give_functional_spec’ method,

render :action => ‘give_functional_spec’

Try this.

I tried this:
def give_functional_spec
render :action => ‘give_functional_spec’
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end
Still its not working…

I tried this:
def give_functional_spec
render :action => ‘give_functional_spec’
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end
Still its not working…

if you are opening the give_functional_spec.rhtml’ page by directly
giving the URL in the browser, then what i said will not be applicable.

How do you render the ‘give_functional_spec.rhtml’?
Are you redirecting from any method or directly giving the url in the
browser like,

http://localhost:3000/cis/give_functional_spec

???

Karthi kn wrote:

I tried this:
def give_functional_spec
render :action => ‘give_functional_spec’
@software_ci= SoftwareCi.find(params[:id])
@software_ci.functional_spec= params[:ci]
@software_ci.save
end
Still its not working…

if you are opening the give_functional_spec.rhtml’ page by directly
giving the URL in the browser, then what i said will not be applicable.

How do you render the ‘give_functional_spec.rhtml’?
Are you redirecting from any method or directly giving the url in the
browser like,

http://localhost:3000/cis/give_functional_spec

???

Yes, i’m redirecting from another method:
<%= link_to ‘Give Functional Specification’, :controller => ‘ci’,
:action => ‘give_functional_spec’, :id => @software_ci.id, :ci_number =>
params[:ci_number] %>

Yes, i’m redirecting from another method:
<%= link_to ‘Give Functional Specification’, :controller => ‘ci’,
:action => ‘give_functional_spec’, :id => @software_ci.id, :ci_number =>
params[:ci_number] %>

According to me, in this case, it will be better if you use another
method like ‘save_functional_spec’ to save the functional_spec.

Keep the save operation statements in ‘save_functional_spec’ method.

Use the ‘give_functional_spec’ method for finding and rendering the
functional_spec. That may work.

Also,

<%= link_to ‘Give Functional Specification’, :controller => ‘ci’,
:action => ‘give_functional_spec’, :id => @software_ci.id, :ci_number =>
params[:ci_number] %>

in the above statement, you have used ‘params’ in the view file. I dont
think we can use params in a view. It is just for passing the parameters
from view to controller. Check it and try.

Karthi kn wrote:

Yes, i’m redirecting from another method:
<%= link_to ‘Give Functional Specification’, :controller => ‘ci’,
:action => ‘give_functional_spec’, :id => @software_ci.id, :ci_number =>
params[:ci_number] %>

According to me, in this case, it will be better if you use another
method like ‘save_functional_spec’ to save the functional_spec.

Keep the save operation statements in ‘save_functional_spec’ method.

Use the ‘give_functional_spec’ method for finding and rendering the
functional_spec. That may work.

Also,

<%= link_to ‘Give Functional Specification’, :controller => ‘ci’,
:action => ‘give_functional_spec’, :id => @software_ci.id, :ci_number =>
params[:ci_number] %>

in the above statement, you have used ‘params’ in the view file. I dont
think we can use params in a view. It is just for passing the parameters
from view to controller. Check it and try.

It works… Thank you so much.
Actually i did the same method for creating, editing and searching. I
was finding whether there is any alternate method for this. This method
requires 2 rhtml files and 2 methods in the controller. So it may become
more complex in the future if more capabilities have to be implemented.
Thanks…

It works… Thank you so much.
Actually i did the same method for creating, editing and searching. I
was finding whether there is any alternate method for this. This method
requires 2 rhtml files and 2 methods in the controller. So it may become
more complex in the future if more capabilities have to be implemented.
Thanks…

If you are using the same view code in many places, explore on the
examples of partial view files and start using it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs