我有一个大表单,我只是添加了一个文件输入,以允许用户上传图像.
这是新的HTML:
<input type="file" name="file_1" />
<input type="text" name="image_description_1" class="text-input"/>
Run Code Online (Sandbox Code Playgroud)
这是新的_submit函数:
if($this->CI->input->post('file_1')){
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['max_size'] = 2000;
$config['upload_path'] = realpath(APPPATH . '../assets/uploads/avatars');
$this->CI->load->library('upload', $config);
$this->CI->upload->do_upload();
$image_data = $this->CI->upload->data();
$image['description'] = $this->CI->input->post('image_description_1');
$image['user_id'] = $id;
$image['image'] = $image_data['file_name'];
$this->CI->db->insert('report_images',$image);
}
Run Code Online (Sandbox Code Playgroud)
正确提交了description和user_id,但文件丢失了.
我应该做些不同的事吗?不确定出了什么问题.
如果条件成立,我想重定向用户:
\n\nclass ApplicationController < ActionController::Base\n @offline = 'true'\n redirect_to :root if @offline = 'true'\n protect_from_forgery\nend\nRun Code Online (Sandbox Code Playgroud)\n\n编辑\n这就是我现在正在尝试的方法,但没有成功。默认控制器不是应用程序控制器。
\n\nclass ApplicationController < ActionController::Base\n before_filter :require_online \n\n def countdown\n\n end\n\nprivate\n def require_online\n redirect_to :countdown\n end\n\nend\nRun Code Online (Sandbox Code Playgroud)\n\n这会导致浏览器错误Too many redirects occurred trying to open \xe2\x80\x9chttp://localhost:3000/countdown\xe2\x80\x9d. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.
如果我添加&& return,则该操作永远不会被调用。
我正在学习rails,而我只是试图让基础知识失败.
我刚安装了devise并创建了一个家庭控制器.如果我想获得用户数(只返回数据库中的记录数),我应该怎么做家庭控制器?它应该与模型互动,对吗?在可home控制与交互users模型和home模式?或者那是不好的做法?
我知道我可以做一个简单的谷歌搜索,但我有很多问题,Stackoverflow是合法的.:)
再往前走一步?
我如何获得"实时馈送",以便在添加记录时主页上的计数发生变化?
public double Integral(double[] x, double intPointOne, double intPointTwo)
{
double integral = 0;
double i = intPointOne;
do
{
integral += Function(x[i])*.001;
i = i + .001;
}
while (i <= intPointTwo);
return integral;
}
Run Code Online (Sandbox Code Playgroud)
这是一个函数,我必须简单地使用部分的总和来集成x1-x2的函数.如何使这个循环更有效(使用更少的循环),但更准确?
当Function改变每次迭代,但它应该是无关紧要的,因为它的幅度(或边界)的顺序应该保持相对同...
如果我有一个按钮,并且我想使用相同的控制器为默认的"UI页面幻灯片"设置动画,那么在点击"nextbutton"时如何实现?我认为这会奏效,但事实并非如此.
- (IBAction)NextButton:(id)sender
{
[self.navigationController pushViewController:self animated:YES];
NSInteger CurrentQuestionNumber = [QuestionNumber intValue];
NSInteger NewQuestionNumber = CurrentQuestionNumber + 1;
QuestionNumber = [NSString stringWithFormat:@"%d", NewQuestionNumber];
QuestionNumberLabel.text = QuestionNumber;
QuestionLabel.text = [QuestionsList objectForKey:QuestionNumber];
}
Run Code Online (Sandbox Code Playgroud) 我对RoR场景有点新意见......我现在才开始连接点.在你的发展生涯中,你们能给我一些更明确的指导和指导吗?
我无法理解路由,控制器和视图之间的相关性(以及它们如何相互连接).
所以,我有我的控制器的index,show,new,create,destroy方法.和相应的
GET /entries(.:format) entries#index
POST /entries(.:format) entries#create
GET /entries/new(.:format) entries#new
GET /entries/:id/edit(.:format) entries#edit
GET /entries/:id(.:format) entries#show
PUT /entries/:id(.:format) entries#update
DELETE /entries/:id(.:format) entries#destroy
Run Code Online (Sandbox Code Playgroud)
为什么我添加一个新方法,vote_up或者vote_down例如,以及具有匹配操作名称的视图,它不起作用.
1)添加新操作并将其连接到视图的正确方法是什么?2)奖金使这些方法与ajax兼容的正确方法是什么(用ajax渲染部分)?如果用户没有启用js会发生什么?
我可以根据我得到的答案扩展/发展这个问题.
我已经厌倦了谷歌搜索自定义动作路线等类似的东西来大杂烩我的应用程序.它正在流失和糟糕的形式,我终于达到理解语言的水平 - 我已经100%自学了...所以请尽量理解你是否可以为一个年轻的padawan.
如果我有一个生产数据库,其中"类型"存储为字符串,但我想将该列转换为整数enum.
我用google搜索/ SO'd,我看到我可以CAST,但不确定那究竟是什么.
如果它不难,我会喜欢使用rails enum,但除此之外,也许我应该坚持我的字符串架构......
请指教!
我已经苦苦挣扎了大约5个小时,试图了解Shrine为什么阻止了我的上传。我要么在强参数中收到诸如“神殿:无效文件”之类的错误,要么出现“预期数组但有字符串”之类的错误。如果没有错误,则实际上不会保存图像。
require "image_processing/mini_magick"
class ImageUploader < Shrine
include ImageProcessing::MiniMagick
plugin :activerecord
plugin :backgrounding
plugin :cached_attachment_data
plugin :determine_mime_type
plugin :delete_raw
plugin :direct_upload
plugin :logging, logger: Rails.logger
plugin :processing
plugin :remove_attachment
plugin :store_dimensions
plugin :validation_helpers
plugin :versions
Attacher.validate do
validate_max_size 2.megabytes, message: 'is too large (max is 2 MB)'
validate_mime_type_inclusion ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
end
def process(io, context)
case context[:phase]
when :store
thumb = resize_to_limit!(io.download, 200, 200)
{ original: io, thumb: thumb }
end
end
end
Run Code Online (Sandbox Code Playgroud)
class Image < ActiveRecord::Base
include ImageUploader[:image] …Run Code Online (Sandbox Code Playgroud) c# ×1
codeigniter ×1
controller ×1
css ×1
enums ×1
html ×1
integration ×1
ios ×1
iphone ×1
methods ×1
performance ×1
photoshop ×1
radio-button ×1
reroute ×1
shrine ×1
textures ×1
uiview ×1
upload ×1
xcode ×1