Retaining values even after form submit in ROR [closed] - ruby-on-rails

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying to create a simple calculator application .
calculator.html.erb
<input type=text name="operand_one" value="0"></td>
<input type=text name="operand_two" value="0"></td>
.
.
.
<input type=text name="output" value="<% =#result %>"></td>
I am able to get the output correctly but the values of the first two text boxes changes to 0 , I need to know how to retain these values ..

You're hardcoding the value to "0" with this part of the code
value="0"
you could change the lines to
<input type=text name="operand_one" value="#value_one"></td> #etc...
and in your controller
#value_one = 0 unless X
but X depends on how your controller works - do you go to a new action to solve the problem in the calculator? if so you'll have to use the params hash.
Not related to the question, but why are you using text for your calculation fields? and are you hard coding that html or it's just the output?

Related

drawerOpened property dont work in vaadin [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I use litElement with vaadin and have next code
<vaadin-app-layout .drawerOpened='false'>
<vaadin-drawer-toggle slot="navbar" ></vaadin-drawer-toggle>
<vaadin-tabs selected="-100" slot="drawer" orientation="vertical" theme="minimal" style="margin: 0 auto; flex: 1;">
${this.renderTabsDependOnStatusAccess()}
</vaadin-tabs>
<div class="content" >
<div id="outlet"></div>
</div>
</vaadin-app-layout>
but my vaadin-drawer-toggle component is still open, how can I make it private by default and wats wrong with my example
I've not used this component, but I'll guess that in JS it's drawerOpened while in HTML it's drawer-opened. Also, boolean attributes are usually present or not, so instead of drawer-opened="false" you probably just remove it. Plain drawer-opened would be true.
If this HTML or in the LitElement render()? In the latter you may want to use ?drawer-opened="${this.isDrawerOpen}" and toggle a property this.isDrawerOpen

Razor view Html.ActionLink icon [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I need to add an icon near myLink in razor view,
in .html page i use ` Requête optimisée.
Now i have
#Html.ActionLink("Requete optimisée", "Index", "Requete")
Dont know where to add my icon .
I wouldn't use ActionLink and would do the following:
<a href="#Url.Action("Index","Requete")" class="my-link-class">Requete optimisée
<div class="my-icon"><img src="#Url.Content("~/icon.jpg")" alt="Icon Image" /></a>
More code but also more freedom and control over what is going on.
If you want show an icon just put a img tag before your link:
<img src="~/Content/Images/Image.png" />
#Html.ActionLink("Requete optimisée", "Index", "Requete")
And if you want to display image link then use this:
#Html.ActionImage("Requete optimisée", "Requete", "~/Content/Images/Image.png")

rails how to declare a variable and store a value in html.erb [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
hi i have a value like this in html.erb
<img src="<%= file.title, file_path(file) %>" alt=""/>
but when I placed the above code it throws an error
SyntaxError in Files#index
the error comes on file_path(file) section . Is there a way to accomplish this ? like declare a variable and assign it to something ?
Though I did not get whay you are trying to achieve but you can try to do it like this
<img src="<%= "#{file.title}, #{file_path(file)}" %>" alt=""/>
You should declare file (a better naming is #file) in the controller action which is associated with this view. There you can do whatever you want with your variable.

Passing a list from a view to a controller? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm a relatively new Rails developer with a heavy Java/C# background and I'm trying to pass multiple time ranges from my view to my controller. For instance, the user could select the time range 9:00am to 11:00am as well as 2:00pm to 4:00pm. The first thing to came to mind was a list of times or a list of key value pairs so that I know when a time range starts and ends. I'm having trouble figuring out how to pass this information to my Rails controller though.
Is there an ideal Rails way of passing a list to a controller?
From Rails Guide http://guides.rubyonrails.org/action_controller_overview.html
request
GET /mytime?t[]=1&t[]=2&t[]=3
in view
<form method="GET" action="mytime">
<select multiple name="t[]">
<option value="1">1:00pm</option>
<option value="2">2:00pm</option>
<option value="3">3:00pm</option>
</select>
</form>
or
<form method="GET" action="mytime">
<input type="text" name="t[]">
<input type="hidden" name="t[]" value="11">
</form>
#in mytime_controller.rb
def index
params[:t] # return Array of values
end
You pass information from a view to a controller via http query string ('get') or form data ('post').
I would consider multi-select dropdown for this case.
Instead of dropdown i suggest you should create a cool for using some jquery plugin that will improve your application's user experience and yes create a rails form and submit it then you can have information in your controller.
Now is you are saving these selected time, that i think you should do then create a model if you haven't already and use form_for else your can use form_tag for your rails application.
Visit Here and find some time picker that suits you need.

slim dynamic conditional class [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Just to help other developers, because there is no similar question on SO.
div class=(is_active? ? 'active' : 'inactive')
div class=('active' if is_active?)
See the examples below:
div class=(is_active? ? 'active' : 'inactive')
div class=('active' if is_active?)
The same approach can be used to assign dynamic values to other attributes.
I use array of classes and nil element if there is no need to include class in list, then compact array to remove nil elements and finally join all together.
div class=(["cday", "col-md-1", day.day == 1 ? "col-md-offset-#{day.cwday-1}" : nil].compact.join(' '))
If you have multiple conditions I am doing right now something like
div class=(('foo ' if is_foo?) + ('bar' if is_bar?))
Though I feel it to be a blemish if is_bar? return false and the generated HTML results in
<div class="foo "></div>
(the blemish is the blank character after the foo). If someone had a solution for that would be awesome.

Resources